Monday, April 27, 2015

Constant in C Programming Language and Rules for Constructing Constant


variable and constant in c programming,primary constant,secondary constant,integer,real,float,character,array,structure,pointer,union,enum and rules for constructing constant


Constant - An entity that does not change known as constant.

                            In c programming constant can be divided into 2 major categories :

                            1. Primary Constant :-

                                Here primary constant is further categorized into 3 types.
                                
                                1.Integer
                                2.Real
                                3.Character




                            2. Secondary Constant :-

                                Secondary constant is also further divided into below categories.
                                
                                1. Array
                                2. Pointer
                                3. Structure
                                4. Union 
                                5. Enum




In C programming,there are some rules for constructing constant:

1. Rules for constructing integer constant:

Rules for constructing integer constant are as follows:

1. An integer constant must contain at least one digit.
2. An integer must not have a decimal point
3. An integer can be either positive or negative.
4. If an integer does not precedes any sign it is assumed to be positive.
5. Commas and blanks are not allowed.
6. The range of an integer constant depends upon the type of compiler.
             For Example- 
                                   For gcc and visual studio compiler -2147483648 to +2147483647
                                  For turbo c or turbo c++ compiler is -32768 to 32767.






2. Rules for constructing real constant:-





Also known as floating point constant .
 
             These constant have 2 forms :-
A) Fractional form
B) Exponential form      

A) Rules for constructing fractional form real constant:-

1. Constant must have at least one digit.
2. Constant must have a decimal point.
3. Can be either positive or negative .
                4. If no sign precedes it is assumed to be positive.
5. Commas and blanks are not allowed.
For ex. +325.24 

B) Rules for constructing exponential form real constant:-

Exponential real constant represented in 2 parts.
1. First part before "e" known as mantissa.
2. Part after "e" known as exponent.
For ex. 0.22e4

a) Both the parts mantissa and exponent should be separated by a alphabet "e" or "E".
b) Mantissa part may have a positive or negative sign default will be positive.
c) Exponent part must have at least one digit which must be positive or negative integer,        default will be positive.
d) Range of exponential form is -3.4e38 to 3.4e38

3. Rules for constructing character constant:-

a) a character constant contains a single alphabet,a single digit or a single special symbol enclosed within single inverted commas.
b) both inverted commas should point to left.