Wednesday 18 April 2012

Constants


The proper combination of alphabets, digits and special symbols form Constants, Variables and Keywords is called Constant.


Constant is a value which does not change.


Types of  Constants


C Constants consist of two types.


Primary Constants
Secondary Constants
Primary Constants further consist of two types.
Integer Constant
Real Constant
Character Constant
Secondary Constants can be divided into:


Array
Pointer
Structure
Union
Enum etc.
Rules for Constructing Integer Constants


An integer constant must have at least one digit.


It should not have a decimal point.
It can be either positive or negative.
If no sign is put with 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.
The range of an Integer constant depends upon the compiler.


For a 16-bit compiler like Turbo C or Turbo C++ the range is –32768 to 32767.
For a 32-bit compiler the range is greater.


Eg. - +6045
         859
         -2922
         
Rules for Constructing Real Constants


They are further classified into two types.


Fractional form and Exponential form.


FRACTIONAL FORM:
A real constant should have at least one digit.
It should always 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.
Eg. - +568.23
         652.32
         -54.6


EXPONENTIAL FORM:


The real constant is represented in two parts in Exponential Form. The part appearing before ‘e’ is called mantissa, whereas the part following ‘e’ is called exponent.
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.
Eg. - +6.4e-5
         -0.3e+6
Rules for Constructing Character Constants


A character constant is a single alphabet, a single digit or a single special symbol which is enclosed within single inverted commas. Both the inverted commas should be pointing to the left. Eg. - ’J’ is a valid character constant whereas ‘J’ is not.
The maximum length of a character constant can be 1 character.


Eg.- 'J'
       'M'
       '8'
       '='


0 comments: