Monday, 8 June 2015

different types of c constants

Types Of C Constants 

alltechprograms
C Constants can be divided into two major Categories.

  • Primary Constants

  • Secondary Constants

Primary Constants : Integer Constant , Real Constant , Character Constant.

Secondary Constants: Array, Pointer,Structure,Union,Enum,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 is assumed to be positive.
  5. no commas or or blanks are allowed with in an integer constant.
  6. the allowable range for integer constants is -32768 to 32767

Rules For Constructing Real Constants

Real Constants are often called Floating point constants.The real Constants Could be Written in two forms

  1. Fractional form 
  2. Exponential form

Rules :

Constants Expressed in fractional form

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

Constants Expressed in Exponential form

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

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.Both the inverted commas should point to the left.
  2. For Example, 'A' is a valid character constant whereas 'A' is not.
  3. The Maximum length of a character constant can be 1 character.


No comments:

Post a Comment