Constants in C language can be divided into two major categories:
- Primary Constants
- Secondary Constants
These constants are further classified as shown in Figure
At this stage we restricted only the primary discussions Constants, that is, whole constants, real and character. Let us see the details of each of these constants. For their construction different types of constants have been established certain rules. These rules are as follows:
Rules for building integer constants
- An integer constant must have at least one digit.
- It must not have a decimal point.
- It can be positive or negative.
- If no sign precedes an integer constant, it is assumed to be
positive. - No commas or blanks are allowed in a integer constant.
- The allowed range for the whole constants is from -32768 to 32767.
True speaking the range of an integer Constants in C language depends on compiler. For a 16-bit compiler, such as Turbo C or Turbo C ++, the range is -32768 to 32767. For a 32-bit compiler, the range would be even larger. Question like what exactly do you mean by a 16-bit or 32-bit compiler, what range of an integer constant is related to the compiler type and such questions are discussed in detail in Chapter 16. Until when will I upposed to work with a 16-bit compiler.
Ex.: 426 +782 -8000 -7605
Rules for Constructing Real Constants
Real constants are often called floating constants. The real
constants can be written in two forms: the fractional form and
Exponential form.
The following rules must be followed while building the real one
constants expressed in fractional form:
- A real constant must have at least one digit.
- It must have a decimal point.
- It can be positive or negative.
- The default sign is positive.
- No commas or semi-fabricates are allowed within a real constant.
Ex.: +325.34 426.0 -32.76 -48.5792
The exponential form of representation of real constants is usually used if the value of the constant is either too small or too high. This one however, it does not in any way restrict us from exponential use the form of representation for other real constants.
In exponential form of representation, the real constant is represented in two parts. The part that appears before the “e” is called mantissa, while the next part “e” is called an exponent.
The following rules must be followed while building the real one constants expressed in exponential form:
- The mantis part and the exponential part should be separated by a letter e.
- The lace part can have a positive or negative sign.
- The default sign of the mantissa part is positive.
- The exponent must have at least one digit, which must be a positive or negative integer. The default sign is positive.
- The range of real constants expressed in exponential form is -3.4e38 to 3.4e38.
Ex.: +3.2e-5 4.1e8 -0.2e+3 -3.2e-5
Rules for building character constants
A character constant is a single alphabet, a single digit, or a special symbol enclosed in single inverted commas. Both inverted commas should point to the left.
For example, “A” is a valid character constant, while “A” is not.
The maximum length of a character constant can be 1 character.
Ex.: 'A' 'I' '5' '='/*54745756836*/