# Constant In Fortran

 A constant is a number which does not change till the end of a program. As we know in algebra 1, 2, 3,………etc are constant which have same value as it is given and cannot be changed. Just like that Fortran language have also constant whose value does not vary up to the end of a program Example: 1 1234 89.43 It is clear from the above example that the value of 1 or 1234 or 89.43 will be always same and will never change. Types of constants a) Integer constants Whole numbers without any fractional parts are called Integer constants. All integer constant must have at least one digit without decimal point. The largest integer constant depends on the computer being used. For IBM PCs and 32 bit work stations the range is + – 2147483647 If – or + sign is not given then according to the rule the sign will be considered as positive. Example: 1 7463 +8677 -986 etc. It is wrong to show integer constant Example: .4 (decimal should not be given) 133.07 (decimal point is not allowed) b) Real constants or Floating point constants Real constant or Floating constant are same. Users should not confuse about these name. They may have fractional parts. Rules of Real Constants Rule 1 A Real constant in a fractional form must have at least one digit and must be written with a 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. Example: 1.3 74.04 -42.6 This means only +, – or . (decimal point) are allowed. It is wrong to show: 1 (decimal point is must otherwise it will be an integer constant) It should be written as: 1.0 Rule 2 A Real constant in the exponent form consists of a mantissa and an exponent. The mantissa must have at least one digit and a decimal point. The mantissa is followed by the latter 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. Example: 134.E04 123.0E4 -123.456E+54 etc. c) Character Constants A character constant is any sequence or group of characters enclosed in apostrophes The group of characters enclosed between apostrophes (‘), is known as character constant or literal constant. An apostrophes is only a control character and it may appear in a constant as control character Example: ‘A’, ‘ASDF’, ‘RAM’, ‘X+Y+Z’, etc Apostrophes themselves are represented using two apostrophes. e.g. SHIV’S FRIEND can be represented as: ‘SHIV”S FRIEND’
Scroll to Top