“Constant are those that do not change while executing the program.”
BASIC deals with two types of constant:
- Numeric constant
- String constant
All numbers belong to this category because their values remain constant. They make take any of the following forms:
+95 (positive integer)
95 (positive integer)
62.5 (positive real)
-135 (negative integer)
-0.7 (negative real)
1.32E+5 (1.32*105 )
-5E-2 (-5 * 10-2)
The notation E stands for “times 10 to the power”. This would appear in computer output whenever the magnitude of a number to be output is quite large, or a number is very close to zero. The exponent can be either positive or negative but cannot be real number. Further, the length of the exponent is limited to two digits.
While writing constant, it is worth remembering the following points:
- A number can normally have up to a maximum of eight digits. However, the varies with the system and therefore the system manual should be consulted for correct size.
- Commas are not allowed in a numeric constant.
- The use of + sign is optional but – sign should be used if the number is negative.
- The length of exponent should not be more than two digits and it can contain – or + sign. Again + sign is optional.
- BASIC does not make any distinction between integer and fractional numbers.
A String constant is any set of valid BASIC characters enclosed in quotation marks. The Quotation marks do not form part of the string.
Strings are used to represent non-numeric information such as names of persons and places, addresses, days, months and years, etc.
Some examples are:
“Aug 15, 2012”
“12 + 27”