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: -

  1. An integer constant must have at least one digit.
  2. It must not have a decimal point.
  3. It can be either positive or negative.
  4. If no sign precedes an integer constant, it is assumed to be positive.
  5. No commas or blanks are allowed within an integer constant.
  6. 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: -

  1. Real constant must have at least one digit.
  2. It must have a decimal point.
  3. It could be either positive or negative.
  4. Default sign is positive.
  5. 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: -

  1. A Character Constant is a single alphabet, a single digit or a single special symbol enclosed within single inverted commas.
  2. The maximum length of a character constant can be 1 character.