Constants or literals in C: Character, Integer, Floating point, Hexadecimal and octal constants

Constants are the fixed values in a C program. Different types of constants:

1) Character constant: Each character constant is enclosed in quotes. Example ‘%”.

2) Integer constants: These are defined as numbers without fractions. Example: 5 and -20.

3) Floating point constants: These are defined by decimals. Example 23.45.

4) Hexadecimal and Octal constants: An 8 based number system is called a s octal number system. Here digits 0 to 7 are used. Base 16 number system is known as hexadecimal. Here digits 0 to 9 and letters from A to F are used. A hexadecimal constant is defined 0x followed by the constant and an octal constant is defined by beginning with zero. For Example:

int hex = 0x25

int  oct = 015

Leave a Reply