C CONSTANTS –
As the name suggests, Constant is a value that we can’t change during execution of the program. Furthermore, we can define C Constant by the following definition..
“A Constant is a fix value that the program can’t alter.. Constants can be of any fundamental data types. The way compiler represents each constant depends upon its type.“
The another name for constant is LITERAL..
Generally, we can categorise Constants through the following..
The following image represents the categorisation of C Constants.
Primary Constants include the following constants,
- INTEGER CONSTANT
- REAL CONSTANT
- CHARACTER CONSTANT
Furthermore, Secondary Constants include,
- UNION, etc.
Generally, we will be focusing on each and every PRIMARY CONSTANT..
INTEGER CONSTANT –
Integer constants are the primary Constants which are generally whole numbers having no decimal point. Furthermore, there are three types of integer constants on the basis of different number systems. The permissible characters which we can use in these constants are :
DECIMAL CONSTANTS – 0,1,2,3,4,5,6,7,8,9 ( Base 10 )
OCTAL CONSTANTS – 0,1,2,3,4,5,6,7 ( Base 8 )
HEXADECIMAL CONSTANTS – 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F ( Base 16 )
Now, some examples of Valid Decimal Integer constants are..
Similarly, some examples of Invalid Decimal Integer constants are..
Because ( . ) is an illegal character.
- 50 3
Because there should be no blank space between the numbers.
Because ( # ) is an illegal character.
Because the first digit can never be zero.
Because there should be no comma between the numbers.
Talking about Octal Integer constants, the First digit must be 0. For example,
Finally, in Hexadecimal Integer constants the first two characters should be 0x or 0X. Some examples are,
In Integer constants, the default type of the constant is int. Also, if the value of Integer constant exceeds, then the type is unsigned int or long int.