Constant:
The alphabets, numbers and special symbol when properly a combined from constants and variables and keywords. A constant is an entity that does not change where as a variable is an entity that may change.
Types of C Constant:
C constant can be divided in two major categories :
1) Primary constant.
2) Secondary constant.
These constant are further divide as
Primary constant :
a) Integer constant
b) Real constant
c) Character constant
d) Sting constant.
Secondary constant :
a) Array
b) Pointer
c) Structure
d) Union
e) Enum etc.
Rules for constructing integer constants:
1) An integer constant must have at least one digit.
2) It must have one decimal point.
3) It can either be positive or negative.
4) If no sign than integer is considered to be positive.
5) No commas or blanks are allowed with in an integer constant.
6) The allowable range of an integer constant is -32768 to 32767.
For example:
512, +126, -24 etc.
Rules for constructing real constants:
Real constant are often called floating points constant. The real constants could be written in two forms Fractional form and Exponential form.
1) A real constant must have digit.
2) It must have decimal point.
3) It could be either positive or negative.
4) Default sign is positive.
5) No commas or blanks are allowed with in a real constant.
For example:
+56.23, -456.01,76.875,-53792.1 etc
Exponential form of representation of real constant :
In exponential form of representation of real constant is represented in two parts . The part appearing before "e" is called mantissa, where as the part following "e" is called exponent.
Following rules must be observed while constructing real constant 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 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.
For Example:
+3.2e-5,4.1e8,-0.2e+3 etc.
Rules for constructing character constant :
1) A character constant is a single alphabet, a single digit or a single special symbol enclosed with in single inverted commas. both the inverted commas should point to the left.
2) The maximum length of character constant can be 1 character.
for example
*A*