Type system and type checking
. If both the operands of arithmetic operators +, -, x are integers then the result is of type integer
. The result of unary & operator is a pointer to the object referred to by the operand.
- If the type of operand is X the type of result is pointer to X
. Basic types: integer, char, float, boolean
. Sub range type : 1 . 100
. Enumerated type: (violet, indigo, red)
. Constructed type: array, record, pointers, functions
In Pascal, types are classified under:
1. Basic types: These are atomic types with no internal structure. They include the types boolean, character, integer and real.
2. Sub-range types: A sub-range type defines a range of values within the range of another type. For example,
type
A = 1..10;
B = 100..1000;
U = 'A'..'Z';
3. Enumerated types: An enumerated type is defined by listing all of the possible values for the type. For example:
type
Colour = (Red, Yellow, Green);
Country = (NZ, Aus, SL, WI, Pak, Ind, SA, Ken, Zim, Eng);
Both the sub-range and enumerated types can be treated as basic types.
4. Constructed types: A constructed type is constructed from basic types and other basic types. Examples of constructed types are arrays, records and sets. Additionally, pointers and functions can also be treated as constructed types.
|