Constants In C

The difference between variable and constants is that variable can change their value at any time but constants can never change their value. Usages of constants can stop the programmer from changing the value of an item by mistake.

C has four basic types of constants. They are:

  • • integer constants
  • • floating – point constants
  • • character constants
  • • string constants

Integer constants
  • • It is an integer – valued number.
  • • Commas and blank spaces are not allowed within it.
  • • It can be preceded by either a minus (-) sign or plus (+) sign. If no sign will be mentioned it is assumed to be positive.
  • • No decimal point is allowed within it.
  • • It can not exceed specified minimum and maximum bound (i.e. – 32, 768 to 32,767).

A decimal integer constant can consists of any combination of digits from 0 through 9. If the constant contains two or more digits, the first digit must be other than 0. For example:

300, -200, +86


A octal integer constant can consists of any combination of digits from 0 through 7. However, the first digit must be 0, in order to identify the constant as an octal number. For example:

012, 0643, 072


A hexadecimal integer constant must begin with either 0x or 0X. It can then followed by any combination digits from 0 to 9 and a through f (either upper – or lowercase).

The declaration of variable must begin with either 0x or 0X. It can then followed by any combination digits from 0 to 9 and a through f(either uppercase or lowercase)

Note that the letters a through f(or A through F) represents 10 through 15 respectively. For example:

0x7, 0Xf2, 0x5D


An unsigned integer constant can be identified by appending the letter U (either upper – or lowercase ) to the end of the constant. For example:

600U, 730u


A Long integer constant can be identified by appending the letter L (either upper- or lowercase ) to the end of the constants. For example

723L, 7000 1


An unsigned long integer constant can be identified by appending the letter UL (either upper – or lowercase ) to the end of the constant. However the U must precede L. For example:

123456UL


Floating – point constants
  • • It must have a decimal point or an exponent (or both).
  • • It may have either positive (+) sign or negative (-) sign. If no sign is mentioned, it assumed as positive.
  • • No commas or blank spaces are allowed.
  • • It must be a base- 10 number.

For example
0.23, 5., 2E-8


Character constants

A character constant is a single character, enclosed in apostrophes (single quotation marks).

For example:
‘A’ ‘b’ ‘9’ ‘@’ ‘ ‘


Certain nonprinting character, and certain characters like backslash (\), the apostrophe (‘)can be expressed in the form of escape sequence. Such escape sequence like newline in C, represented as \n, represent single character. For example:

‘\n’ ‘\b’ ‘\\ ‘ ‘\t ‘


String constants

A string constant of any number of constants of consecutive characters (including none) enclosed in (double) quotation marks. For example:

“Alok” , “Amiya 123” , “Santosh\n”



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext