Constants
Constants in C which does
not change its value during the execution of a program
Real or Floating-point
constant
A real constant is
combination of a whole number followed by a decimal point and
the fractional
part.
Example: 45.22 , 0.45 , -4.56 ,
.76 , 341.
The Real or Floating-point constants can be
written in two forms:
1. Normal
or Fractional form
2. Exponential
form
Express a Real constant in fractional form
A real constant
consists for a series of digits representing the whole part of the number,
followed by a decimal point, the decimal cannot be omitted.
Valid Real constants
(Fractional): -4.45 +645.916 0.0 5.
Invalid Real constant:
-
4
-
a decimal point is missing
1,3
- Illegal character
(,)
Rules for Constructing Real Constants
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 +ve or -ve.
4. Default sign is +ve.
5. Commas or blanks are not
allowed within a real constant.
Express a real constant in Exponential
form
If the value of a constant
is either too small or too large, exponential form of representation of real
constants is usually used.
In exponential form, the real constant is
represented in two parts.
Mantissa - The part
appearing before e, the mantissa is either a real number expressed in
decimal notation or an integer.
Exponent - The part following e, the exponent is an integer with an optional plus
or minus sign followed by a series of digits. The letter e separating the
mantissa and the exponent can be written in either lowercase
or uppercase.
For Example – 54000000
we can write 54 x 106 ---Ã 54E6
or
5.4 x 107 ---Ã 5.4E7
or 0.54 x 108 --Ã 0.54E8
Rules for Constructing Real Constants
in Exponential Form
1. The mantissa part and the exponential
part should be separated by letter in
exponential form
2. The mantissa
part may have a positive or negative sign.
3. Default sign of
mantissa part is positive.
4. The exponent
part 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 for is -3.4e38 to
3.4e38.
0 Comments