- 2.2.7.3. -
Table of Contents
2. TMT Pascal Language Description
2.2. Pascal Language Structure
2.2.7. Declarations
2.2.7.3. Constant Declarations
2.2.7.3. Constant
Declarations
There are two types of constants and TMT Pascal interprets them
both differently.
Constants that are declared without a type may not be changed in the program.
Constants that are typed are the same as variables (described below),
however they contain an initial value. These constants may be changed in
the program. A constant declaration is preceded bythe const
reserved word.
const
identifier [:IdentifierType] = expression;
Identifier is the actual name of the constant defined.
IdentifierType, which is optional, specifies the type of the constant.
Again, if a type is specified, the constant is the same as a variable with
an initial value.
Expression is assigned to the constant and must be evaluated at
compile time. The following are untyped constants and may not be modified:
const
Digit = '0'..'9';
MaxSize = 100;
Msg = 'This is a string constant';
Typed constants may be of any type except for file, procedure, or function.
Some examples of typed constants are:
type
Coordinate = record
x,y: Integer;
end;
const
Originpos: Coordinate = (x:0; y:0);
Name : String = 'Hello World!';
StrSize : Integer = 100;
Ary : array [False..True] of Byte = (10,15);
See also:
Integer and Real Number Constants
String Constants
- 2.2.7.3. -