Constants in c
Constants in C are the fixed values that are used in a program, and its value remains the same during the entire execution of the program. The Constants in C are applicable to the values, which do not change during the execution of a program. C constants can be divided into two major categories:
- Primary Constants
- Secondary Constants
Primary constants are of three types.
- Integer Constant
- Real Constant
- Character Constant
Integer constants are the sequence of numbers from 0 to 9 without decimal points or fractional part or any other symbols.
Ex.: 5, 15, -20 etc.
Rules for Constructing Integer Constants: -
- An integer constant must have at least one digit.
- It must not have a decimal point.
- It can be either positive or negative.
- If no sign precedes an integer constant, it is assumed to be positive.
- No commas or blanks are allowed within an integer constant.
- The allowable range for integer constants is -32768 to 32767.
Real constant are often called Floating constants. The real constants could be written in two forms: -
- Fractional form.
- Exponential form.
Ex.: 5.5, 15.213, 3.14 etc.
Rules for Constructing Real Constants: -
- Real constant must have at least one digit.
- It must have a decimal point.
- It could be either positive or negative.
- Default sign is positive.
- No commas or blanks are allowed in real constants.
Character Constant is a single character.
Ex.: ‘A’, ‘S’, ‘5’, ‘=’ etc.
Rules for Constructing Character Constants: -
- A Character Constant is a single alphabet, a single digit or a single special symbol enclosed within single inverted commas.
- The maximum length of a character constant can be 1 character.