Constants: the items whose value do not change during program execution.
The constants include Integer, Real and Character constants.
Rules for constructing Integer Constants
Rules for constructing Real Constants
Rules for constructing Character constant
Examples : 'A', '9', '='
The constants include Integer, Real and Character constants.
Constant type
|
Permissible Range
|
Integer Constant
|
-2147483648 (231) to 2147483647 (231-1)
|
Real Constant
|
-3.4*1038 to 3.4*1038
|
Character Constant
|
Can have maximum length of 1
|
Rules for constructing Integer Constants
- Should have at least one digit.
- It must not have a decimal point.
- Can be either positive or negative.
- If no sign precedes a number, it is taken positive.
- No commas or blanks are allowed within the Integer Constant.
Valid Integer Constants
|
Invalid
|
4284
|
4,284
|
-38482
|
4 285
|
+42873
|
792.654
|
Rules for constructing Real Constants
- Should have at least one digit.
- Must have a decimal point.
- Can be either positive or negative.
- Default sign is positive.
- No commas or blanks allowed.
- Big real constants can be expressed in exponential form.
- The mantissa and exponential part is separated by letter e or E.
- Default sign for mantissa and exponent sign is positive.
0.000738 = 7.38
* 10-4
Here 7.38 is
the Mantissa part
And 10-4
is the Exponent part
In exponential
form it can be written as
7.38e-4 Or
7.38E-4
Valid Real Constants
|
Invalid
|
8912.12
|
4284
|
0.1231
|
4 285 . 06
|
-2371.001
|
Five.seven
|
-0.25
|
1,000.7
|
+3.2e5
|
4.3e
|
-4.32e-7
|
2E
|
3.55E-5
|
4,009E
|
-234.01E+6
|
2 e 21
|
Rules for constructing Character constant
1.
Must be enclosed without single quotation marks.
2.
Must be of maximum length 1.
3.
Can be a alphabet, a number or a special symbol.
Examples : 'A', '9', '='
No comments:
Post a Comment