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:
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
For example
0.23, 5., 2E-8
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 ‘
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”
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