The constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals.
Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are also enumeration constants as well.
The constants are treated just like regular variables except that their values cannot be modified after their definition.
Note: - we will cover secondary Constants in sebsequent chapters.
.
Rules for Constructing Constants.
Integer
E.g. 426, +782, -9000, -7605
Real / Float
Real constants are often called Floating Point constants. The real constants could be written in two forms—Fractional form and Exponential form.
For Fractional Form
E.g. +325.34, 426.0 , -32.76, -48.5792
For Exponential Form
The exponential form of representation of real constants is usually used if the value of the constant is either too small or too large.
In exponential form of representation, the real constant is represented in two parts. The part appearing before ‘e’ is called mantissa, whereas the part following ‘e’ is called exponent.
Range of real constants expressed in exponential form is -3.4e38 to 3.4e38.
E.g. +3.2e-5, 4.1e8, -0.2e+3, -3.2e-5
Character Constant
E.g. 'A', 'I', '5', '='