The Constants in C language refers to fixed values that do not change during the execution of the program.
Constants in C
The constants in C programming are of two types:
- Numeric Constants
- Character Constants
Numeric Constants
All integer and real number constants are called numeric constants.
Integer Constants
Numeric constants without a floating point is called integer constant. There are three type of integer constants.
- Decimal integer constant
- Octal integer constant
- Hexa-decimal integer constant
Examples: 123, -321, 0, 654321, +89
Real Number Constants
The numeric constants with floating point are called real constants.
Examples: 0.00567, 0.85, 400.567, -0.87, .78
Character Constants
A single character or a sequence of characters enclosed within quotes is called character constant. There are two types of character constants:
- Single character constant
- String constant
Single Character Constant
A single character enclosed within a pair of single quotes is called single character constant.
Examples: ‘2’ , ‘b’ , ‘:’
String Constants
A sequence of characters are enclosed within a pair of double quotes is called string constant.
Examples: “Hello CSAdeeb” , “120+5” , “a” , “how..?”
Declaring a Variable as Constant
A variable in C language can be declared as constant using the keyword const at the time initialization.
Example:
const int maximum_mark = 100;