CONSTANTS
The term constant means that it does not change during the execution of a program con- stants may be classified as:
(i) Integer Constant
(ii) Floating point Constant
Integer Constant
Integer constants are whole numbers without any fractional parts. There are three types of
Integer constant:
(i) Decimal constant (base 10)
(ii) Octal Constant (base 8)
(iii) Hexa decimal constant(base 16)
Allowed digit in decimal constant 0,1,.2,3,4,5,6,7,8,9,. The digits of one octal constant can be
0,1,2,3,4,5,6,7 and that in hexadecimal constants are 0,1,2,3,4,5,6,7,8.9,A,B,C,D,E,F,
Rule for decimal constant
A decimal integer constant must have at least one digit and must be written without a decimal point. The first digit in the constant should not be 0. It may have either sign + or -. If either sign does not precede to the constant it is assumed to be positive.
Following are valid decimal integer constants: (i) 12345
(ii) 3468
(iii) -9746
The following are invalid decimal integer constants :-
(i) 11. ( Decimal point not allowed ) (ii) 45,256(comma not allowed )
(iii) $ 125 ( currency symbol not allowed )
(vi) 025 ( first digit should not be 0 for a decimal integer ) (v) ƒ 248 ( first symbol not a digit )
Octal Constant
An octal constant must have at least one digit and start with the digit 0. It must be written without a decimal point. It may have either sign + or -. A constant which has no sign is taken as positive.
The following are valid octal constants.
(i) 0245
(ii) - 0467
(iii) +04013
The following are invalid octal constants
(i) 25( Does not begin with 0 )
(ii) 0387 ( 8 is not an octal digit )
(iii) 04.32 (Decimal point not allowed )
Hexadecimal constant
A hexadecimal constant must have at least one hexadecimal digit and start with Ox or OX. It may have either sign
The following are valid hexadecimal constants
(i) OX 14 AF
(ii) OX 34680
(iii) – OX 2673E
The following are invalid hexadecimal constants:
(i) Ox14AF
(ii) OX34680
(iii) -Ox2673E
The following are invalid hexadecimal constants:
(i) 0345 (Must start of Ox)
(ii) 0x45H3 (H not a hexa decimal digit)
(iii) Hex 2345 (Ox defines a hexadecimal number, not Hex)
Floating Point Constants
A floating point constant may be written in one or two forms could fractional form or the exponent form, the rules for writing a floating point constant in these two forms is given as follows.
Rule (Fractional Form)
floating point constant in a fractional form must have at least one digit to the right of the decimal point. It may have either the + or the - sign preceding it. If a sign does not precede it then it is assumed to be positive.
Following are valid floating point constants:
(i) 1.0
(ii) –0.5678
(iii) 5800000.0
(iv) –0.0000156
Following are invalid:
(i) 1 (Decimal point missing)
(ii) 1. (No digit following decimal point)
(iii) -1/2, (Symbol/illegal)
(iv) .5 (No digit to the left of the decimal)
(v) 58, 678.94 (Comma not allowed)
Rule (Exponential form)
A floating point constant in the exponent form consists of a mantissa and an exponent. The mantissa must have at least one digit. It may have a sign. The mantissa is followed by the letter E or e and the exponent. The exponent must be an integer(without a decimal point) and must have at least one digit. A sign for the exponent is optional.
The following are valid floating point constants in exponent form:
(i) (a) 152 E08 (b) 152.0 E8 (c) 152 e+8
(d) 152 E+08 (e) 15.2 e9 (f) 1520 E7
(ii) -0.148E-5
(iii) 152.859 E25 (iv) 0.01540 e05
The following are invalid:
(i) 152.AE8 (Mantissa must have a digit following).
(ii) 152*e9 (* not allowed).
(iii) +145.8E (No digit specified for exponent).
(iv) -152.9E5.5 (Exponent can not be a fraction).
(v) 0.158 E+954 (Exponent too large).
(vi) 125, 458.25 e-5 ( comma not allowed in mantissa).
(vii) 02E8 (A digit must precede in mantissa).
The term constant means that it does not change during the execution of a program con- stants may be classified as:
(i) Integer Constant
(ii) Floating point Constant
Integer Constant
Integer constants are whole numbers without any fractional parts. There are three types of
Integer constant:
(i) Decimal constant (base 10)
(ii) Octal Constant (base 8)
(iii) Hexa decimal constant(base 16)
Allowed digit in decimal constant 0,1,.2,3,4,5,6,7,8,9,. The digits of one octal constant can be
0,1,2,3,4,5,6,7 and that in hexadecimal constants are 0,1,2,3,4,5,6,7,8.9,A,B,C,D,E,F,
Rule for decimal constant
A decimal integer constant must have at least one digit and must be written without a decimal point. The first digit in the constant should not be 0. It may have either sign + or -. If either sign does not precede to the constant it is assumed to be positive.
Following are valid decimal integer constants: (i) 12345
(ii) 3468
(iii) -9746
The following are invalid decimal integer constants :-
(i) 11. ( Decimal point not allowed ) (ii) 45,256(comma not allowed )
(iii) $ 125 ( currency symbol not allowed )
(vi) 025 ( first digit should not be 0 for a decimal integer ) (v) ƒ 248 ( first symbol not a digit )
Octal Constant
An octal constant must have at least one digit and start with the digit 0. It must be written without a decimal point. It may have either sign + or -. A constant which has no sign is taken as positive.
The following are valid octal constants.
(i) 0245
(ii) - 0467
(iii) +04013
The following are invalid octal constants
(i) 25( Does not begin with 0 )
(ii) 0387 ( 8 is not an octal digit )
(iii) 04.32 (Decimal point not allowed )
Hexadecimal constant
A hexadecimal constant must have at least one hexadecimal digit and start with Ox or OX. It may have either sign
The following are valid hexadecimal constants
(i) OX 14 AF
(ii) OX 34680
(iii) – OX 2673E
The following are invalid hexadecimal constants:
(i) Ox14AF
(ii) OX34680
(iii) -Ox2673E
The following are invalid hexadecimal constants:
(i) 0345 (Must start of Ox)
(ii) 0x45H3 (H not a hexa decimal digit)
(iii) Hex 2345 (Ox defines a hexadecimal number, not Hex)
Floating Point Constants
A floating point constant may be written in one or two forms could fractional form or the exponent form, the rules for writing a floating point constant in these two forms is given as follows.
Rule (Fractional Form)
floating point constant in a fractional form must have at least one digit to the right of the decimal point. It may have either the + or the - sign preceding it. If a sign does not precede it then it is assumed to be positive.
Following are valid floating point constants:
(i) 1.0
(ii) –0.5678
(iii) 5800000.0
(iv) –0.0000156
Following are invalid:
(i) 1 (Decimal point missing)
(ii) 1. (No digit following decimal point)
(iii) -1/2, (Symbol/illegal)
(iv) .5 (No digit to the left of the decimal)
(v) 58, 678.94 (Comma not allowed)
Rule (Exponential form)
A floating point constant in the exponent form consists of a mantissa and an exponent. The mantissa must have at least one digit. It may have a sign. The mantissa is followed by the letter E or e and the exponent. The exponent must be an integer(without a decimal point) and must have at least one digit. A sign for the exponent is optional.
The following are valid floating point constants in exponent form:
(i) (a) 152 E08 (b) 152.0 E8 (c) 152 e+8
(d) 152 E+08 (e) 15.2 e9 (f) 1520 E7
(ii) -0.148E-5
(iii) 152.859 E25 (iv) 0.01540 e05
The following are invalid:
(i) 152.AE8 (Mantissa must have a digit following).
(ii) 152*e9 (* not allowed).
(iii) +145.8E (No digit specified for exponent).
(iv) -152.9E5.5 (Exponent can not be a fraction).
(v) 0.158 E+954 (Exponent too large).
(vi) 125, 458.25 e-5 ( comma not allowed in mantissa).
(vii) 02E8 (A digit must precede in mantissa).