C-Constants

What is Constant in C Language?

Constant in C refers to a value which cannot be changed i.e. a fixed value, like – 5, 5.6, “C Language”, 'C' etc.

What are the types of C constant?

Primarily there are 3 types of C constant:

  1. Integer Constant
  2. Real Constant
  3. Character Constant

What are the rules of constructing Integer constant?

The rules of constructing Integer constant are as follows:

  1. An integer constant must have at least one digit.
    Ex: 3
  2. It must not have a decimal point.
    Ex: 3.5 is wrong
  3. It can be either positive or negative.
    Ex: +45 or -45
  4. If no sign precedes an integer constant it is assumed to be positive.
    Ex: 67 is by default positive
  5. No commas or blanks are allowed within an integer constant.
    Ex: 6,7 and 6 7 are wrong
  6. The allowable range for integer constants is -32768 to 32767 in case of a 16 bit compiler
    Ex: 3563467 or -6575855 is out of range of integer in case of 16 bit compiler

What are the rules of constructing real or floating point constant?

  1. A real constant must have at least one digit.
    Ex: 3.0
  2. It must have a decimal point.
    Ex: 45.65
  3. It could be either positive or negative.
    Ex: +34.54 or -35.76
  4. Default sign is positive.
    Ex: 453.76 s by default positive
  5. No commas or blanks are allowed within a real constant.
    Ex: 6.,7 and 6. 7 are wrong
  6. The real constant can also be written as exponential form like 65.45e6, where the part before 'e' is known as mantissa and the part after e is called exponent.
  7. 7. The mantissa part must have decimal point whereas the exponent part must be an integer
  8. Both the mantissa part, and the exponent part may have a positive or negative sign, default is positive.
  9. Range of real constants expressed in exponential form is -3.4e38 to 3.4e38.

What are the rules of constructing Character constant?

  1. Any single alphabet or single digit or single special symbol enclosed within the single inverted comma is treated as character constant.
    Ex: 'b' or 'B' or '5' or '-' etc
    but '45' or 'fs' or '=-' are wrong because they enclose more than a single character.
15:00
Check Page Rank