Types of C Constants

C constants can be divided into two major categories:

  • Primary Constants
  • Secondary Constants
Types of C Constants
Types of C Constants

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

Ex.: 426
+782
-8000
-7605

Rules for Constructing Real Constants

Real constants are often called Floating Point constants. The real constants could be written in two forms—Fractional form and Exponential form

Following rules must be observed while constructing real constants expressed in fractional form

  • A 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 within a real constant.

Ex.: +325.34
426.0
-32.76
-48.5792

Following rules must be observed while constructing real constants expressed in exponential form:

  • The mantissa part and the exponential part should be separated by a letter e
  • The mantissa part may have a positive or negative sign.
  • Default sign of mantissa part is positive.
  • The exponent must have at least one digit, which must be a positive or negative integer. Default sign is positive.
  • Range of real constants expressed in exponential form is -3.4e38 to 3.4e38.

Ex.: +3.2e-5
4.1e8
-0.2e+3
-3.2e-5

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. Both the inverted commas should point to the left. For example, ’A’ is a valid character constant whereas ‘A’ is not.
  • The maximum length of a character constant can be 1 character

Ex.: ‘A’
‘I’
‘5’
‘=’

Leave a Comment