What are data types in Pascal for?

When programming in Pascal, you must select the data types of the Pascal program. It is important for the programmer to understand that in order to run his program in RAM, a place is allocated for storing not only the commands, but also the data with which these commands work.

data types in pascal
All data types in Pascal are divided into two groups: simple and structured. For each data type, a certain number of bytes is allocated. Simple types include: integer types (byte, integer, etc.), real types (real, single, etc.), a logical type (boolean), a character type (char), an enumerated and an interval type. All of them, with the exception of real types, are ordinal types and are characterized by the fact that they have a limited ordered set of values. For example, a variable of type byte can take values ​​in the range from 0 to 255 inclusive. Such data types in Pascal allow you to use the functions Pred (calculates the previous value) and Succ (calculates the next value), Low (calculates the smallest type value) and High (calculates the largest type value), Ord (calculates the serial number of the current value of the variable).

A simple type variable has only one given value, i.e. single integer, fractional number or single character. Variables that have simple data types in Pascal should be described in the Var section (abbreviated from Variables - Variables).

pascal data types
A variable in a Pascal program is considered fully defined if it has a name (identifier), type, and initial value. The name of the variable is used when accessing it through any operator. The data type determines the range of representation (what values ​​a variable can take), the operations in which it can participate, the amount of memory that is required to store the variable in RAM. Therefore, when solving the problem, one should be inclined to reduce the number of variables and rational selection of their types.

Structured types are an ordered set of variables of simple types. These include: arrays (arrays), sets (set of), strings (string), files (file), records (record). Pascal's structured data types are described in the type section (type description section).

An array is the most common of structured types; it is used when it is required to store and process an ordered set of variables of the same type (any simple type). Arrays are one-dimensional, two-dimensional, multidimensional. An example of a one-dimensional array is the list of students in a classroom journal, sorted alphabetically, where each student has a unique serial number. An example of a two-dimensional array is the location of seats in the cinema's auditorium (each seat is determined by two dimensions - row number and seat number).

pascal data types

Elements of a set, unlike an array, are unordered, and the number of elements is limited to 255. A string is an ordered set of characters and this is very similar to an array, however, only characters can be elements of a string.

A file is the same array, but the number of elements in it can change as the program runs. A record is a collection of heterogeneous data.

By learning to apply data types in Pascal, you can implement quite complex and interesting tasks.

Source: https://habr.com/ru/post/K18860/


All Articles