A constant is a value which will not change during the execution of a program.
Constants are those values in programming language which cannot be modified once they are defined. They are fixed values in a program.
In C program we can define constants in two ways as below:-
Using #define preprocessor directive:- This directive is used to declare an alias name for existing variable or any value. Example:-#define identifierName Value.
Using a const keywords:- using const keyword to define constants is as simple as defining variables, the difference is you will have to precede the definition with a const keyword.
Example:-const int var = 5;
Types of C Constants:-
Integer Constant:- An integer is a whole number without any decimal point or a fraction part. No extra characters are allowed other than ‘+’ and ‘-‘ sign.
The integer Constants are divided into three types:-
Decimal (10, 140, -140 etc.)
Octal(010, 0140, 0440 etc.)
Hexadecimal(0x8A, 0xAB, 0xA123)
Enumeration Constants:- A set of named integer constants( The name given to integer constants) defined using the keyword enum are called enumeration constants.
Example:- enum identifier{enumeration-list}; enum boolean {NO, YES};
Floating point constant:- The floating point constants are base 10 numbers with fraction part such as 10.5. All negative numbers should have a prefix ‘-‘. A positive number can have as optional ‘+’ sign. No other extra characters are allowed.
Character Constant:- A symbol enclosed within a pair of single quotes(‘apostrophe denoted by the symbol’) is called a character constant.
String Constant:- A sequence of characters(i.e., one or more characters)enclosed within a pair of double quotes is called a string constant.