Types of variables in Pascal: description, properties, examples

In order for the machine to process whateverthen there is no input, it must "understand" to which type the variables belong, in which the values ​​are entered. In the absence of information on the data format, the computer will not be able to determine whether a particular operation is permissible in a particular case: for example, it is intuitively clear that one can not raise a letter to a power or take an integral of a string. Thus, the user must determine what actions can be performed with each variable.

As in other high-level programming languages, Pascal's variable types are optimized for performing tasks of different directivity, have a different range of values ​​and length in bytes.

Division of types of variables

Types of variables in Pascal are divided into simple andstructured. Real types include real and ordinal types. Structured include arrays, records, sets and files. Pointers, objects and procedural types are separately highlighted.

types of variables in pascal
Consider order and real types. There are 5 integer types, the logical, the symbolic, the enumerated, and the range type.

Ordinal types

There are 5 integer types, differing in length in bytes and range of values.

The length of Byte and ShortInt is 1 byte. The difference between them is that Byte stores only non-negative values, and ShortInt allows you to store and negative (-128 to +127). Similarly, the types of Word and Integer are related, with the only difference being that their size is 2 bytes.

Finally, LongInt allows you to store andnegative, and positive values, using 4 bytes - in the numerical dimension it is 2 in the 16th degree on both sides of zero. Different types of variables in Pascal contribute to the efficient solution of user tasks, since in each specific case both a small and a large range of values ​​may be required, and there may also be limitations on the amount of allocated memory.

string variables in pascal
It is important to understand that zero occupies the same numberplaces in memory, how many and any other number. Thus, when forming a range of values, the minimum negative number modulo will be one more than the positive one: for example, from -128 to +127.

Variables belonging to the logical type (BOOLEAN) can be TRUE (true) or FALSE (false) and require 1 byte of memory.

The CHAR type allows you to store any of the setcharacters that exist in the computer memory. However, in character variables in Pascal, only the code of the character is actually stored, according to which its graphic form is displayed.

Real types

Among the types of variables in Pascal stands outseveral numerical ones with the possibility of recording a fractional part. The difference between the Single, Real, Double and Extended types is reduced to the range of the received values, the number of significant digits after the decimal point and the size in bytes.

In accordance with the order given above, a variable of each type will occupy 4, 6, 8 or 10 bytes.

Arrays

Structured data types are complex and allow you to combine a number of simple values ​​within a single variable. A vivid example is an array that can be specified as follows:

Type

String = array [1..100] of char;

Var Y = String;

So we got a type calledString, which allows you to specify variables of 100 characters in length. In the last line, a one-dimensional array Y, having the type String, is directly defined. The description of variables in Pascal is carried out by placing the identifier on the left side, and on the right, after the equal sign, the values ​​of the variable.

character variables in pascal
The index range, written in square brackets, allows you to access each specific element of the array:

readln (Y [2]);

In this case, we read the second element of the previously created array Y.

A special case of a one-dimensional array is the string variables in Pascal, because the string is a sequence of symbols, that is, elements of the char type.

Records

The entry consists of several fields filled indata of any types except file. In general, a variable of this type is similar to a database element. For example, you can put in the name of the person and his phone number:

type NTel = Record

NAME: String [12];

NUMBER: String [10]

end;

var one: NTel;

The first line to the left shows the type name, andon the right - the service word record. The second line contains a field with a name, in the third a phone number. The word "end" indicates that we have entered all the fields that we wanted, and this completes the process of creating the record.

Finally, in the last line, we set the variable One, which is of type NTel.

You can address both to the record as a whole and to its individual components, for example: one.NAME (i.e., variable_name.field_name).

Files

Pascal allows you to work with text, typed and untyped files, which represent a structured sequence of components that have the same type.

description of variables in pascal

When reading from a file or writing to it, you can use either the full address or its short form:

'File1.DAT'

'C: FolderFile2.txt'

A short form is used when placing a file in a folder where the program itself is stored, referring to it. A complete form can be used in any circumstances.

You can specify a file-type variable as follows:

var

f1: file of integer;

types of variables in pascal
To work with files, differentfunctions and procedures that associate a variable with a file on the disk, opening it for reading, writing and rewriting, closing at the end of the work, allowing you to create a new name and delete the file from the computer.

Finally

Without the ability to use different types of variablesin Pascal, the user will not be able to implement even the simplest task. In order for the program to execute the algorithm without errors, it is required to learn both the service words and the syntax, since the machine knows how to "understand" the commands only if they are written in the only correct way.

</ p>
Liked:
0
Similar articles
The Gauss method: examples of solutions and private
An example of programs in Pascal. Programming
Assignment operator in Pascal: what for
What is a div in Pascal? Additions,
What are the types of data in Pascal?
Standard procedures and functions in Pascal
Structured type - one-dimensional array
Type conversion. Round and Trunc Functions
Constant and variable costs: examples.
Popular Posts
up