Data types
The data type specifies a set whose elements are called values of that type and defines a set of operations with these values. Individual data types differ from each other, but they also create a certain hierarchy (Figure 33).
We assign the data type to the variable in the declaration part (var) and we choose it based on what kind a variable is (integer, real, character, etc.) and what allowed range values the variable acquires.
Scalar data types are characterized by an ordered set of values which are, from the permissible operations point of view, indivisible. They may be further divided into:
- Ordinal - integer,
boolean, char, interval, enumerated,
- Non-ordinal - real.
If the data type is ordinal, we always know what value follows or precedes the current one. For example, we have a whole number and the value is 5. We know for sure that the previous value is 4 and the next is 6. The same is true, for example, also in the alphabet where the characters are always arranged in the same order.
The non-ordinal types are the exact opposite as we do not know for any value of this type to tell what precedes it and what follows. Examples of such numbers are the real numbers, such as 5.5 - we cannot be sure of whether it is or not followed by a number 5.51 or 5.511, or 5.5111, etc.
The common attribute of ordinal data types is that the functions are defined for them:
Ord - serial number in the set of values
Succ - successor
Pred - predecessor