Thursday, January 2, 2014

Constants

Constants: the items whose value do not change during program execution.
The constants include Integer, Real and Character constants.




Constant type
Permissible Range
Integer Constant
-2147483648 (231) to 2147483647 (231-1)
Real Constant
-3.4*10­­38­ to 3.4*1038­
Character Constant
Can have maximum length of 1






 Rules for constructing Integer Constants
  1. Should have at least one digit.
  2. It must not have a decimal point.
  3. Can be either positive or negative.
  4. If no sign precedes a number, it is taken positive.
  5. 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
  1. Should have at least one digit. 
  2. Must have a decimal point.
  3. Can be either positive or negative.
  4. Default sign is positive.
  5. No commas or blanks allowed.
  6. Big real constants can be expressed in exponential form.
  7. The mantissa and exponential part is separated by letter e or E.
  8. 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