What types of variables are used in pascal. Data types in Pascal (variables, constants), their types and description

Ordinal types include (see Figure 4.1) integer, logical, character, enumerated and range types. The ORD(X) function is applicable to any of them, which returns the ordinal number of the value of the expression X. For integer types, the ORD(X) function returns the value of X itself, i.e. ORD(X) = X for X belonging to any shell type. Applying ORD(X) to boolean, character, and enumeration types produces a positive integer in the range 0 to 1 (boolean), 0 to 155 (character), 0 to 65535 (enumeration). A range type retains all the properties of the underlying ordinal type, so the result of applying the ORD(X) function to it depends on the properties of that type.

You can also apply functions to ordinal types:

PRED (X) - returns the previous value of the ordinal type (the value that corresponds to the ordinal number ORD(X) - 1), i.e.

ORD(PRED(X)) = ORD(X) - 1;

SUCC (X) - returns the next ordinal value that matches the ordinal number ORD(X) +1, i.e.

ORD(SUCC(X)) = ORD(X) + 1.

For example, if a program defines a variable

then the PRED(C) function will return the value "4", and the SUCC(C) function will return the value "6".

If we imagine any ordinal type as an ordered set of values, increasing from left to right and occupying a certain segment on the number axis, then the function PRED(X) is not defined for the left, and SUCC(X) for the right end of this segment.

Whole types. The range of possible values ​​of integer types depends on their internal representation, which can be one, two, or four bytes. In table 4.1 shows the name of integer types, the length of their internal representation in bytes and the range of possible values.

Table 4.1

When using procedures and functions with integer parameters, you should be guided by the “nesting” of types, i.e. wherever WORD can be used, BYTE can be used (but not vice versa), LONGINT “includes” INTEGER, which, in turn, includes SHORTINT.

The list of procedures and functions applicable to integer types is given in Table 4.2. Letters b, s, w, i, l expressions of type BYTE, SHORTINT, WORD, INTEGER and LONGINT are designated, respectively, x is an expression of any of these types; letters vb, vs, vw, vi, vl, vx denote variables of the corresponding types. An optional parameter is indicated in square brackets.

Table 4.2

Standard procedures and functions applicable to entire types
Appeal Result type Action
abs(x) x Returns module x
chr(b) Char Returns a character by its code
dec(vx[, i]) - Decreases the value of vx by i, and in the absence of i - by 1
inc(vx[, i]) - Increases the value of vx by i, and in the absence of i - by 1
Hi(i) Byte Returns the high byte of the argument
Hi(w) Same Same
Lo(i) " Returns the low byte of the argument
Lo(w) " Same
odd(l) Boolean Returns True if the argument is an odd number
Random (w) Same as parameter Returns a pseudorandom number uniformly distributed in the range 0...(w-l)
sgr(x) X Returns the square of the argument
swap(i) Integer Swaps bytes in a word
swap(w) Word

When operating with integers, the type of the result will correspond to the type of the operands, and if the operands are of different integer types, the type of the operand that has the maximum power (maximum range of values). Possible overflow of the result is not controlled in any way, which can lead to misunderstandings, for example:

a:= 32767; (Maximum possible INTEGER value)

x:= a + 2; (Overflow while evaluating this expression !}

y:= LongInt(a)+2; (No overflow after casting the variable to a more powerful type)

WriteLn(x:10:0, y:10:0)

As a result of running the program we get

Boolean type. Boolean values ​​can be one of the pre-declared constants FALSE or TRUE. The rules apply to them:

False< True;

succ(False)= True;

pred(True) = False.

Since the Boolean type is an ordinal type, it can be used in a countable type operator, for example:

for 1:= False to True do ....

Character type. The value of a character type is the set of all PC characters. Each character is assigned an integer in the range 0...255. This number serves as the code for the internal representation of the symbol; it is returned by the ORD function.

ASCII code is used for encoding ( American Standard Code for Information Interchange- American Standard Code for Information Interchange). This is a 7-bit code, i.e. it can only encode 128 characters in the range from 0 to 127. At the same time, in the 8-bit byte allocated for storing a character in Turbo Pascal, you can encode twice as many characters in the range from 0 to 255. The first half of the characters PC with codes 0...127 corresponds to the ASCII standard (Table 4.3). The second half of the characters with codes 128...255 are not limited by the rigid framework of the standard and can be changed on different types of PCs (Appendix 2 shows some common encoding options for these characters).

Table 4.3

Character encoding according to the ASCII standard
Code Symbol Code Symbol Code Symbol Code Symbol
NUL B.L. ® "
ZON ! A a
STX " IN b
ETX # WITH With
EOT $ D d
ENQ % E e
ASK & F f
BEL " G g
B.S. ( H h
NT ) I i
LF * J j
VT + k k
FF , L i
CR - M m
SO . N n
S.I. / ABOUT
DEL p P
DC1 Q q
DC2 R r
DC3 S s
DC4 T t
N.A.K. U u
SYN V V
ETB w w
CAN X X
E.M. U U
SUB : z z
ESC / [ {
FS < \ l
G.S. = ] }
R.S. > ^ ~
US ? - n

Characters with codes 0...31 refer to service codes. If these codes are used in the program's character text, they are considered whitespace. When used in I/O operations, they can have the following independent meaning:

Symbol Code Meaning
BEL Call; The display of this symbol is accompanied by a sound signal
NT Horizontal tabulation; when displayed on the screen, moves the cursor to a position that is a multiple of 8 plus 1 (9, 17, 25, etc.)
LF Line translation; when displaying it on the screen, all subsequent characters will be output starting from the same position, but on the next line
VT Vertical tab; when displayed on the screen, it is replaced with a special character
FF Page run; when output to a printer, it forms a page; when output to the screen, it is replaced with a special character
CR Carriage return; entered by pressing the Enter key (when entered using READ or READLN, it means the “Enter” command and is not placed in the input buffer; when output, it means the “Continue output from the beginning of the current line” command)
SUB End of file; entered from the keyboard by pressing Ctrl-Z; when output it is replaced with a special sign
SSC End of work; entered from the keyboard by pressing the ESC key; when output it is replaced with a special sign

Relational operations, as well as built-in functions, are applicable to the CHAR type: СНR(В) - function of the CHAR type; converts an expression B of type BYTE into a character and returns it with its value;

UPCASE(CH) - CHAR type function; returns the uppercase letter if CH is a lowercase Latin letter, otherwise returns the CH character itself, for example:

cl:= UpCase("s") ;

c2:= UpCase ("Ф") ;

WriteLn(cl," ",c2)

Since the UPCASE function does not process Cyrillic, the result of running this

programs will be displayed on the screen

Enum type. An enumerated type is specified by an enumeration of the values ​​it can receive. Each value is named by some identifier and is located in a list surrounded by parentheses, for example:

colors =(red, white, blue);

The use of enumerated types makes programs more visual. If, for example, the program uses data associated with the months of the year, then the following fragment of the program:

TypeMonth=(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);

month: TypeMonth;

if month = Aug then WriteLn("It would be nice to go to the sea!");

It would be, you see, very clear. Alas! In Turbo Pascal you cannot use Cyrillic in identifiers, so we are forced to write like this:

TypeMonth=(jan,feb,mar,may,jun,jul,aug,sep,oct,nov,dec);

month: TypeMonth;

if month = aug then WriteLn("It would be nice to go to the sea!");

The correspondence between the values ​​of an enumerated type and the ordinal numbers of these values ​​is established by the enumeration order: the first value in the list receives the ordinal number 0, the second - 1, etc. The maximum capacity of an enumerated type is 65536 values, so in fact an enumerated type defines a certain subset of the whole WORD type and can be considered as a compact declaration of a group of integer constants with values ​​0, 1, etc.

Using enumerated types increases the reliability of programs by allowing you to control the values ​​that corresponding variables receive. For example, let the following enumerated types be given:

colors = (black, red, white);

ordenal= (one, two, three);

days = (monday, tuesday, Wednesday);

In terms of power and internal representation, all three types are equivalent:

ord(black)=0, ..., ord(white)=2,

ord(one)=0, ...ord(three)=2,

ord(monday)=0, ...ord(Wednesday)=2.

However, if the variables are defined

col:colors; num:ordenal;

then the operators are allowed

num:= succ(two);

day:= pred(tuesday);

but unacceptable

As already mentioned, there is a one-to-one correspondence between the values ​​of an enumerated type and the set of integers, specified by the ORD(X) function. Turbo Pascal also allows the reverse conversion: any expression of type WORD can be converted to a value of an enum type, as long as the value of the integer expression does not exceed the power1™ of the enumeration type. This conversion is achieved by using an automatically declared function with the name of the enumerated type (see section 4.4). For example, for the type declaration discussed above, the following assignments are equivalent:

col:= colors(0);

Of course, assignment

will be unacceptable.

Variables of any enumerated type can be declared without first declaring that type, for example:

col: (black, white, green);

Type-range. A range type is a subset of its base type, which can be any ordinal type except a range type. A range type is defined by the boundaries of its values ​​within the base type:

<мин.знач.>..<макс.знач.>

Here<мин.знач. >- minimum value of the type-range;

<макс.знач.>- its maximum value.

For example:

digit = "0".."9";

The range type does not have to be described in the TYPE section, but can be specified directly when declaring a variable, for example:

Ichr: "A".."Z";.

When determining a range type, you must follow the following rules:

  • two ".." characters are treated as one character, so spaces between them are not allowed;
  • the left border of the range should not exceed its right border. A range type inherits all the properties of its base type, but with the limitations of its lower power. In particular, if a variable is defined

days = (mo,tu,we,th,fr,sa,su);

WeekEnd = sa .. su;

then ORD(W) will return the value 5 while PRED(W) will result in an error.

The Turbo Pascal standard library includes two functions that support working with range types:

HIGH(X) - returns the maximum value of the range type to which the variable X belongs;

LOW(X) - returns the minimum value of the range type.

The following short program will print the line

WriteLn(Low(k),"..",High(k))

The set of integers is infinite, but we can always choose the number of bits to represent any integer that arises when solving a specific problem. The set of real numbers is not only infinite, but also continuous, so no matter how many bits we take, we will inevitably encounter numbers that do not have an exact representation. Floating point numbers are one possible way to represent real numbers, which is a trade-off between precision and range of accepted values.

A floating point number consists of a set of individual digits, conventionally divided into sign, exponent, and mantissa. The exponent and mantissa are integers that, together with the sign, give the following representation of a floating point number:

Mathematically it is written like this:

(-1) s × M × B E, where s is the sign, B is the radix, E is the exponent, and M is the mantissa.

The base determines the digit number system. It has been mathematically proven that floating point numbers with base B=2 (binary representation) are most resistant to rounding errors, therefore in practice only bases 2 and, less commonly, 10 are encountered. For further presentation, we will always assume B=2, and the formula for a number with floating point will look like:

(-1) s × M × 2 E

What is mantissa and order? Mantissa is a fixed-length integer that represents the most significant bits of a real number. Let's say our mantissa consists of three bits (|M|=3). Take, for example, the number “5”, which in the binary system will be equal to 101 2. The most significant bit corresponds to 2 2 =4, the middle bit (which is equal to zero) is 2 1 =2, and the least significant bit is 2 0 =1. Order– this is the power of the base (two) of the highest digit. In our case E=2. It is convenient to write such numbers in the so-called “scientific” standard form, for example “1.01e+2”. It is immediately clear that the mantissa consists of three signs, and the order is two.

Let's say we want to get a fractional number using the same 3 bits of the mantissa. We can do this if we take, say, E=1. Then our number will be equal

1.01e+1 = 1×2 1 +0×2 0 +1×2 -1 =2+0.5=2.5

Obviously, in this way the same number can be represented in different ways. Let's consider an example with the length of the mantissa |M|=4. The number “2” can be represented as follows:

2 = 10 (in binary) = 1.000e+1 = 0.100e+2 = 0.010e+3.

Therefore, already in the very first machines, numbers were represented in the so-called normalized form, when the first bit of the mantissa was always assumed to be equal to one.

This saves one bit (since the implicit one does not need to be stored in memory) and ensures that the number is represented uniquely. In our example, “2” has a single representation (“1.000e+1”), and the mantissa is stored in memory as “000”, because the leading unit is implied implicitly. But a new problem arises in the normalized representation of numbers - it is impossible to represent zero in this form.

  • Data analysis using the Parameter Selection and Solution Search commands
  • Analysis and interpretation of experimental psychological research data.
  • Analysis of source data. Technical standards for city roads.
  • ANALYSIS OF DATA OBTAINED. MAKING A DECISION ABOUT THE SUFFICIENCY OR INSUFFICIENCY OF WATER SUPPLY CHARACTERISTICS FOR THE NEEDS OF THE IRRIGATION SYSTEM.
  • Communication line equipment: data transmission equipment, terminal equipment, intermediate equipment.

  • The lesson covers the main standard data types in Pascal, the concept of a variable and a constant; explains how to work with arithmetic operations

    Pascal is a typed programming language. This means that the variables that store data are of a specific data type. Those. The program must directly indicate what data can be stored in a particular variable: text data, numeric data, if numeric, then integer or fractional, etc. This is necessary primarily so that the computer “knows” what operations can be performed with these variables and how to perform them correctly.

    For example, the addition of text data, or as it is correctly called in programming - concatenation - is the usual merging of strings, while the addition of numeric data occurs bitwise, in addition, fractional and integer numbers are also added differently. The same applies to other operations.

    Let's look at the most common data types in Pascal.

    Integer data types in Pascal

    Type Range Required memory (bytes)
    byte 0..255 1
    shortint -128..127 1
    integer -32768.. 32767 2
    word 0..65535 2
    longint -2147483648..2147483647 4

    You need to keep in mind that when writing programs in Pascal integer(translated from English as a whole) is the most frequently used, since the range of values ​​​​is most in demand. If a wider range is needed, use longint(long integer, translated from English as long integer). Type byte in Pascal it is used when there is no need to work with negative values, the same goes for type word(only the range of values ​​here is much larger).

    Examples of how variables are described (declared) in Pascal:

    program a1; var x,y:integer; (integer type) myname:string; (string type) begin x:=1; y:=x+16; myname:="Peter"; writeln("name: ",myname, ", age: ", y) end.

    Result:
    name: Peter, age: 17

    Comments in Pascal

    Notice how comments are used in Pascal. In the example comments, i.e. service text that is “not visible” to the compiler is enclosed in curly braces. Typically, comments are made by programmers to explain pieces of code.

    Task 3. The population of Moscow is a = 9,000,000 inhabitants. The population of New Vasyuki is b=1000 inhabitants. Write a program that determines the difference in the number of inhabitants between two cities. Use Variables

    Real data types in Pascal

    Real numbers in Pascal and in programming in general are the name for fractional numbers.

    Type Range Required memory (bytes)
    real 2.9 * 10E-39 .. 1.7 * 10E38 6
    single 1.5 * 10 E-45 .. 3.4 * 10E38 4
    double 5 * 10E-324 .. 1.7 * 10E308 8
    extended 1.9 * 10E-4951 .. 1.1 * 10E4932 10

    The real type in Pascal is the most commonly used real type.

    Above were presented simple data types in Pascal, which include:

    • Ordinal
    • Whole
    • brain teaser
    • Character
    • Listable
    • Interval
    • Real

    To display the values ​​of variables of real type, formatted output is usually used:

  • the format uses either one number, indicating the number of positions allocated to this number in exponential form;
  • p:=1234.6789; Writeln(p:6:2); (1234.68)

    Along with simple types, the language also uses structured data types and pointers, which will be the subject of subsequent lessons on Pascal.

    Constants in Pascal

    Often in a program it is known in advance that a variable will take on a specific value and will not change it throughout the execution of the entire program. In this case, you must use a constant.

    The declaration of a constant in Pascal occurs before the declaration of variables (before the var service word) and looks like this:

    An example of a constant description in Pascal:

    1 2 3 4 5 6 const x= 17 ;

    var myname: string ;

    begin myname: = "Peter" ;

    writeln("name: ", myname, ", age: ", x) end.


    const x=17; var myname:string; begin myname:="Peter"; writeln("name: ",myname, ", age: ", x) end.

    Order of operations

    1. evaluation of expressions in parentheses;
    2. multiplication, division, div, mod from left to right;
    3. addition and subtraction from left to right.

    Pascal Standard Arithmetic Procedures and Functions

    Here it is worthwhile to dwell in more detail on some arithmetic operations.

    • The inc operation in Pascal, pronounced increment, is a standard Pascal procedure that means increasing by one.
    • Example of inc operation:

      x:=1; inc(x); (Increases x by 1, i.e. x=2) writeln(x)

      More complex use of the inc procedure:
      Inc(x,n) where x is an ordinal type, n is an integer type; procedure inc increments x by n.

    • The Dec procedure in Pascal works similarly: Dec(x) - decreases x by 1 (decrement) or Dec(x,n) - decreases x by n.
    • The abs operator represents the modulus of a number. It works like this:
    • a: =- 9;

      b:=abs(a);

    • (b=9)
    • a:=-9; b:=abs(a); (b=9)
    • The div operator in Pascal is often used, since a number of tasks involve the operation of whole division.
    • The remainder of division or the mod operator in Pascal is also indispensable for solving a number of problems.

      Noteworthy is Pascal's standard odd function, which determines whether an integer is odd. That is, it returns true for odd numbers, false for even numbers.

    • An example of using the odd function: var x:integer; begin x:=3; writeln(sqr(x)); (answer 9) end.
    • Exponentiation operation in Pascal

      is missing as such. But in order to raise a number to a power, you can use the exp function.

      The formula is: exp(ln(a)*n), where a is a number, n is a degree (a>0).

    However, in the Pascal abc compiler, exponentiation is much simpler: var x:integer; begin x:=9; writeln(sqrt(x)); (answer 3) end.
    Task 4.

    The dimensions of a matchbox are known: height - 12.41 cm, width - 8 cm, thickness - 5 cm. Calculate the area of ​​the base of the box and its volume(S=width*thickness, V=area*height)

    Task 5. The zoo has three elephants and quite a few rabbits, with the number of rabbits changing frequently. An elephant is supposed to eat one hundred carrots a day, and a rabbit - two. Every morning, the zookeeper tells the computer the number of rabbits. The computer, in response to this, must tell the attendant the total number of carrots that need to be fed to the rabbits and elephants today. Task 6. It is known that x kg of sweets costs a rubles Determine how much it costs y kg of these sweets, and also how many kilograms of sweets can be bought at

    The concept of data is one of the key ones in programming, and in computer science in general. Roughly speaking, data in computer science is information that is in a state of storage, processing or transmission over a certain period of time. In Turing machines, information has a type, and this in turn depends on the type of information.

    Data types in Pascal define the possible values ​​of variables, constants, expressions, and functions. They are built-in and custom. Built-in types are initially present in the programming language, and custom types are created by the programmer.

    According to the method of presentation and processing, data types are:

    • simple
    • structured
    • pointers
    • objects
    • procedures

    This article will consider only the simplest data types, since at the initial stages of training, it will be easier for your program to do without, for example, files and records than without integer or string variables.

    Integer type

    This includes several integer types, which differ in the range of values, the number of bytes allocated for storing them, and the word with which the type is declared.

    Type Range Size in bytes
    shortint -128…127 1
    integer -32 768…32 767 2
    longint -2 147 483 648…2 147 483 647 4
    byte 0…255 1
    word 0…65 535 2

    You can declare an integer variable in the Var section, for example:

    All arithmetic and logical operations can be performed on variables in this category with the exception of division (/), which requires a real type. Some standard functions and procedures may also apply.

    Real type

    In Pascal there are the following real data types:

    Type Range Memory, byte Number of digits
    Real 2.9e-39 … 1.7e38 6 11-12
    Single 1.5e-45 … 3.4e38 4 7-8
    Double 5.0e-324…1.7e308 8 15-16
    Extended 3.4e-4932 … 1.1e493 10 19-20
    Comp -9.2e63…(9.2e63)-1 8 19-20

    More operations and functions can be performed on them than on integers. For example, these functions return a real result:

    sin(x) – sine;

    cos(x) – cosine;

    arctan(x) – arctangent;

    ln(x) – natural logarithm;

    sqrt(x) – square root;

    exp(x) – exponent;

    Boolean type

    A variable of a Boolean data type can take only two values: true and false. Here, true corresponds to the value 1, and false corresponds to zero. You can declare a Boolean variable like this:

    Comparison and logical operations can be performed on data of this type: not, and, or, xor.

    Character type

    A character data type is a collection of characters used in a particular computer. A variable of this type takes the value of one of these characters and occupies 1 byte in computer memory. Word Char defines a value of this type. There are several ways to write a character variable (or constant):

    1. as a single character enclosed in apostrophes: ‘W’, ‘V’, ‘p’;
    2. by specifying the character code, the value of which must be in the range from 0 to 255.
    3. using the ^K construction, where K is the control character code. The value of K must be 64 greater than the corresponding control character code.

    Relational operations and the following functions are applicable to values ​​of a character data type:

    Succ(x)- returns the next character;

    Pred(x)- returns the previous character;

    Ord(x)- returns the value of the character code;

    Chr(x)- returns the value of a symbol by its code;

    UpCase(x)- converts letters from the interval ‘a’..’z’ to upper case.

    To work effectively with a character type, I recommend using .

    String type

    A string in Pascal is a sequence of characters enclosed in apostrophes, and is denoted by the word String. The number of characters (line length) must not exceed 255. If the length of the line is not specified, it will automatically be determined to be 255 characters. The general form of a string variable declaration looks like this:

    Var<имя_переменной>:string[<длина строки>];

    Each character in a line has its own index (number). The index of the first byte is 0, but it does not store the first character, but the length of the entire string, which means that a variable of this type will occupy 1 byte more than the number of variables in it. The number of the first character is 1, for example, if we have the string S=‘stroka’, then S=s;. In one of the following lessons, the string data type will be discussed in more detail.

    Enumerated data type

    An enumerated data type represents a limited number of identifiers. These identifiers are enclosed in parentheses and separated by commas.

    Type Day=(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);

    Variable A can only take the values ​​specified in the Type section. You can also declare a variable of enumerated type in the Var section:

    Var A: (Monday, Tuesday);

    Relational operations are applicable to this type, and it is predetermined that Monday

    Interval data type

    When it is necessary to specify a range of values, then in such situations the interval data type is used. The construction used for the declaration is m..n, Where m is the minimum (initial) value, and n– maximum (final); here m and n are constants, which can be of integer, character, enumeration or boolean type. Values ​​of interval type can be described both in the types section and in the variable description section.

    General form:

    TYPE<имя_типа> = <мин. значение>..<макс. значение>;

    Federal Agency for Education

    Essay

    "DATA TYPES IN PASCAL"

    1. Data types

    Any data, i.e. constants, variables, properties, function values ​​or expressions are characterized by their types. A type defines the set of valid values ​​that an object can have, as well as the set of valid operations that can be applied to it. In addition, the type also determines the format of the internal representation of data in the PC memory.

    In general, the Object Pascal language is characterized by a branched structure of data types (Fig. 1.1). The language provides a mechanism for creating new types, thanks to which the total number of types used in a program can be as large as desired.

    The data processed in the program is divided into variables, constants and literals:

    Constants represent data whose values ​​are set in the constant declaration section and do not change during program execution.

    Variables are declared in the variable declaration section, but unlike constants, they receive their values ​​during program execution, and these values ​​can be changed. Constants and variables can be referred to by name.

    Literal has no identifier and is represented directly by the value in the program text.

    Type defines the set of values ​​that data elements can take and the set of operations allowed on them.

    This and the four subsequent chapters provide detailed descriptions of each type.

    1.1 Simple types

    Simple types include ordinal, real, and datetime types.

    Ordinal types differ in that each of them has a finite number of possible values. These values ​​can be ordered in a certain way (hence the name of the types) and, therefore, each of them can be associated with some integer - the ordinal number of the value.

    Real types, strictly speaking, also have a finite number of values, which is determined by the format of the internal representation of a real number. However, the number of possible values ​​of real types is so large that it is not possible to associate an integer (its number) with each of them.

    Date-time type designed to store date and time. In fact, it uses the real format for these purposes.

    1.1.1 Ordinal types

    Ordinal types include (see Figure 1.1) integer, logical, character, enumerated, and range types. The Ord(x) function can be applied to any of them, which returns the ordinal number of the value of the expression X.


    Rice. 1.1 - Data type structure

    For whole types, the function ord(x) returns the value of x itself, i.e. Ord(X) = x for x belonging to any whole type. Applying Ord(x) to logical , symbolic and enumerable types gives a positive integer in the range 0 to 1 ( boolean type), from 0 to 255 ( symbolic), from 0 to 65535 ( enumerable). Type-range preserves all the properties of the base ordinal type, so the result of applying the ord(x) function to it depends on the properties of this type.

    You can also apply functions to ordinal types:

    pred(x)- returns the previous value of the ordinal type (the value that corresponds to the ordinal number ord(x) -1, i.e. ord(pred(x)) = ord(x) - 1;

    succ(x)- returns the next value of the ordinal type, which corresponds to the ordinal number ord(x) +1, i.e. ord(Succ(x)) = ord(x) + 1.

    For example, if a program defines a variable

    then the function PRED(c) will return the character "4", and the function SUCC(c) will return the character "6".

    If we imagine any ordinal type as an ordered set of values ​​increasing from left to right and occupying a certain segment on the number axis, then the function pred(x) is not defined for the left end, and succ (x) is not defined for the right end of this segment.

    Integer types . The range of possible values ​​of integer types depends on their internal representation, which can be one, two, four, or eight bytes. In table 1.1 shows the names of integer types, the length of their internal representation in bytes and the range of possible values.

    Table 1.1 - Integer types

    Name Length, bytes Range of values
    Cardinal 4 0. .. 2 147 483 647
    Byte 1 0...255
    Shortint 1 -128...+127
    Smallint 2 -32 768...+32 767
    Word 2 0...65 535
    Integer 4
    Longint 4 -2 147 483 648...+2 147 483 647
    Int64 8 -9*1018...+9*1018
    LongWord 4 0. . .4 294 967 295

    Types LongWord And Int64 were first introduced in version 4, and the types Smallint And Cardinal not available in Delphi 1. Type integer for this version it takes 2 bytes and has a value range from -32768 to +32767, i.e. the same as Smallint .

    When using procedures and functions with integer parameters, you should be guided by the “nesting” of types, i.e. wherever it can be used word, allowed to use Byte(but not vice versa), in Longint“enters” Smallint, which in turn includes Shortint .

    The list of procedures and functions applicable to integer types is given in table. 1.2. The letters b, s, w, i, l denote expressions of the following types: Byte , Shortint, Word, Integer and Longint ,

    x is an expression of any of these types; the letters vb, vs, vw, vi, vl, vx denote variables of the corresponding types. An optional parameter is indicated in square brackets.

    Table 1.2 - Standard procedures and functions applicable to entire types

    Appeal Result type Action
    abs(x) Task 6. Returns module x
    chr(b) Char Returns a character by its code
    dec(vx[,i]) - Decreases the value of vx by i, and in the absence of i - by 1
    inc(vx[,i]) - Increases the value of vx by i, and in the absence of i - by 1
    Hi(w) Byte Returns the highest bow of the argument
    Hi(I) Same Returns the third byte
    Lo(i) Returns the low byte of the argument
    Lo(w) Same
    odd(l) Boolean Returns True if the argument is an odd number
    Random(w) Same as parameter Returns a pseudorandom number uniformly distributed in the range 0...(w-l)
    sqr(x) X Returns the square of the argument
    swap(i) Integer Swaps bytes in a word
    swap(w) Word Same

    When operating with integers, the result type will correspond to the type of the operands, and if the operands are of different integer types, the general type that includes both operands. For example, when operating with shortint And word the common type will be integer. In the default setting, the Delphi compiler does not produce code to check whether a value is out of range, which can lead to misunderstandings.

    Boolean types . Logical types include Boolean, ByteBool, Bool, wordBool And LongBool. In standard Pascal, only the type is defined Boolean, other logical types are introduced into Object Pascal for compatibility with Windows: types Boolean And ByteBool each takes up one byte, Bool And WordBool- 2 bytes each, LongBool- 4 bytes. Boolean values ​​can be one of the pre-declared constants False or True.

    Since the Boolean type is an ordinal type, it can be used in a loop statement of a countable type. In Delphi 32 for Boolean meaning

    Ord (True) = +1, while for other types ( Bool, WordBool etc.)

    Ord(True) = -1, so these kinds of operators should be used with caution! For example, for Delphi 6 version, the executable showMessage(" --- ") statement in the following loop for will never be executed:

    for L:= False to True do

    ShowMessage("--);

    If we replace the loop parameter type L in the previous example with Boolean, the loop will run and the message will appear on the screen twice. [For Delphi versions 1 and 2 ord (True) =+1 for any boolean type.]

    Character type . The value of a character type is the set of all PC characters. Each character is assigned an integer in the range 0...255. This number serves as the code for the internal representation of the symbol; it is returned by the ord function.

    For encoding in Windows, the ANSI code is used (named after the American National Standard Institute, the American standardization institute that proposed this code). The first half of PC characters with codes 0... 127 corresponds to Table 1.3. The second half of characters with codes 128...255 varies for different fonts. Standard Windows fonts Arial Cyr, Courier New Cyr and Times New Roman use the last 64 codes (from 192 to 256) to represent Cyrillic characters (without the letters “ё” and “Ё”): “A”... “Z” are encoded values ​​192..223, “a”... “i” - 224...255. The symbols “Ё” and “е” have codes 168 and 184, respectively.

    Table 1.3 - Character encoding in accordance with the ANSI standard

    Code Symbol Code. Symbol Code. Symbol Code Symbol
    0 NUL 32 B.L. 64 @ 96 "
    1 ZON 33 ! 65 A 97 A
    2 STX 34 66 IN 98 b
    3 ETX 35 # 67 WITH 99 With
    4 EOT 36 $ 68 D 100 d
    5 ENQ 37 % 69 E 101 e
    6 ACK 38 & 70 F 102 f
    7 BEL 39 " 71 G 103 d
    8" B.S. 40 ( 72 N 104 h
    9 HT 41 ) 73 I 105 i
    10 LF 42 * 74 J 106 j
    11 VT 43 + 75 TO 107 y
    12 FF 44 F 76 L 108 1
    13 CR 45 - 77 M 109 m
    14 SO 46 78 N 110 n
    15 S.I. 47 / 79 0 111 O
    16 DEL 48 0 80 R 112 P
    17 DC1 49 1 81 Q 113 q
    18 DC2 50 2 82 R 114 r
    19 DC3 51 3 83 S 115 s
    20 DC 4 52 4 84 T 116 t
    21 N.A.K. 53 5 85 U 117 u
    22 SYN 54 6 86 V 118 v
    23 ETB 55 7 87 W 119 W
    24 CAN 56 8 88 X 120 Task 6.
    25 E.M. 57 9 89 Y 121 U
    26 SUB 58 : 90 Z .122 z
    27 ESC 59 ; 91 t 123 {
    28 FS 60 < 92 \ 124 1
    29 G.S. 61 = 93 ] 125 }
    30 R.S. 62 > 94 L 126 ~
    31 US 63 F 95 127 r

    Characters with codes 0...31 refer to service codes. If these codes are used in the program's character text, they are considered whitespace.

    To type char relational operations are applicable, as well as built-in functions:

    Char (c)- type function char; converts an expression to type Byte into a symbol and returns it with its value;

    UpCase(CH)- type function char; returns a capital letter if сн is a lowercase Latin letter, otherwise returns the symbol сн itself (for Cyrillic it returns the original character).

    Enum type . An enumerated type is specified by an enumeration of the values ​​it can receive. Each value is named by some identifier and is located in a list surrounded by parentheses, for example:

    colors = (red, white, blue);

    The use of enumerated types makes programs more visual.

    The correspondence between the values ​​of an enumerated type and the ordinal numbers of these values ​​is established by the enumeration order: the first value in the list receives the ordinal number 0, the second - 1, etc. The maximum capacity of an enumerated type is 65536 values, so in fact the enumerated type specifies some subset of the whole type word and can be considered as a compact declaration of a group of integer constants with values ​​0, 1, etc.

    Using enumerated types increases the reliability of programs by allowing you to control the values ​​that corresponding variables receive. Object Pascal allows the reverse conversion: any expression of type Word can be converted to a value of an enumerated type unless the value of the integer expression exceeds the cardinality of that type. This conversion is achieved by using an automatically declared function with the name of the enumerated type.

    Type-range . A range type is a subset of its base type, which can be any ordinal type except a range type.

    A range type is defined by the boundaries of its values ​​within the base type:

    <мин.знач.>..<макс.знач.>

    Here<мин. знач. >- minimum value of the type-range;<макс. знач. >- its maximum value.

    The range type does not have to be described in the type section, but can be specified directly when declaring the variable.

    When determining a range type, you must follow the following rules:

    two “..” characters are treated as one character, so spaces between them are not allowed; the left border of the range should not exceed its right border.

    A range type inherits all the properties of its base type, but with the limitations of its lower power. In particular, if a variable is defined.

    The Object Pascal standard library includes two functions that support working with range types:

    High(x)- returns the maximum value of the range type to which variable x belongs;

    Low(x)- returns the minimum value of the range type.

    1.1.2 Real types

    Unlike ordinal types, whose values ​​are always mapped to a series of integers and are therefore represented absolutely precisely in PC, the values ​​of real types define an arbitrary number only with some finite precision depending on the internal format of the real number.

    Table 1.4 - Real types

    In previous versions of Delphi 1...3 type Real occupied 6 bytes and had a range of values ​​from 2.9*10-39 to 1.7*1038. In versions 4 and 5 this type is equivalent to type Double. If required (for compatibility reasons) use 6-byte Real, you need to specify a compiler directive (SREALCOMPATIBILITY ON).

    As can be seen from table. 1.4, a real number in Object Pascal occupies from 4 to 10 contiguous bytes and has the following structure in PC memory.

    Here s is the sign digit of the number; e - exponential part; contains binary order; m is the mantissa of the number.

    Mantissa m has a length of 23 (for single) up to 63 (for Extended) binary bits, which ensures an accuracy of 7...8 for single and 19...20 for Extended decimal digits. The decimal point (comma) is implied before the left (most significant) digit of the mantissa, but when operating on a number, its position is shifted to the left or right in accordance with the binary order of the number stored in the exponential part, therefore operations on real numbers are called floating point (comma) arithmetic .

    Note that the arithmetic coprocessor always processes numbers in the format Extended, and the three other real types in this case are obtained by simply truncating the results to the required size and are used mainly to save memory.

    Types occupy a special position in Object Pascal comp And Currency, which are treated as real numbers with fractional parts of a fixed length: in comp the fractional part has a length of 0 digits, i.e. it is simply absent, in currency the length of the fractional part is 4 decimal places. In fact, both types define a large signed integer that stores 19...20 significant decimal digits (internally they occupy 8 contiguous bytes). At the same time, in expressions comp And currency are fully compatible with any other real types: all real operations are defined on them, they can be used as arguments to mathematical functions, etc. The most suitable area of ​​application for these types is accounting calculations.

    1.1.3 Date-time type

    The datetime type is defined by a standard identifier TDateTime and is designed to simultaneously store both date and time. In the internal representation it occupies 8 bytes and similar currency is a real number with a fixed fractional part: the integer part of the number stores the date, and the fractional part stores the time. The date is defined as the number of days that have passed since December 30, 1899, and the time as the fraction of a day that has passed since 0 hours, so the value 36444.837 corresponds to the date 10/11/1999 and the time 20:05. The number of days can be negative, but values ​​smaller than -693594 (corresponding to the date 00.00.0000 from the Nativity of Christ) are ignored by functions for converting a date to a string type.

    Above data type TDateTime the same operations are defined as on real numbers, and expressions of this type can involve constants and variables of integer and real types.

    Because the type TDateTime compatible with the format of real numbers, you can easily determine a date that is several days ahead or back from a given one: to do this, it is enough to add or subtract the desired integer from the given date, respectively.

    1.2 Structured types

    Any of the structured types (and in Object Pascal there are four of them: arrays, records, sets and files) is characterized by the multiplicity of elements that form this type. Each element, in turn, can belong to a structured type, which allows us to talk about possible nesting of types. Object Pascal allows arbitrary depth of nesting of types, but the total length of any of them in the internal representation should not exceed 2 GB.

    For compatibility with standard Pascal, Object Pascal allows a reserved word to be placed before a structured type declaration packed, instructing the compiler to save whenever possible the memory allocated for objects of a structured type; but the compiler actually ignores this instruction: “packing” data into Object Pascal is done automatically wherever possible.

    1.2.1 Arrays

    Arrays in Object Pascal are in many ways similar to similar data types in other programming languages. A distinctive feature of arrays is that all their components are data of the same type (possibly structured). These components can be easily organized and any one of them can be accessed simply by specifying its serial number.

    The array type description is specified as follows:

    <имя типа>= array [<сп.инд.типов>] of<тип>;

    Here<имя типа>- correct identifier; array, of- reserved words (array, from);<сп.инд.типов>- a list of one or more index types, separated by commas; square brackets framing the list are a syntax requirement;<тип>- any type of Object Pascal.

    Any ordinal types with a capacity of no more than 2 GB can be used as index types in Object Pascal (i.e., except LongWord And Int64)

    The depth of nesting of structured types in general, and, consequently, of arrays, is arbitrary, so the number of elements in the list of index types (array size) is not limited, however, the total length of the internal representation of any array cannot be more than 2 GB. In PC memory, array elements follow each other in such a way that when moving from low to high addresses, the rightmost index of the array changes most quickly.

    In Object Pascal, you can use a single assignment operator to transfer all the elements of one array to another array of the same type.

    1.2.2 Records

    Record is a data structure consisting of a fixed number of components called fields of a record. Unlike an array, the components (fields) of a record can be of different types. To make it possible to refer to one or another component of a record, the fields are named.

    The structure of a post type declaration is:

    <имятипа>=record<сп.полей>end;

    Here<имя типа>- correct identifier; record/end- reserved words (record, end);<сп.полей>- list of fields; is a sequence of sections of a record separated by a semicolon.

    Each section of a record consists of one or more field identifiers, separated by commas.

    Offer case...of, which opens the variant part, is superficially similar to the corresponding selection operator, but in fact only plays the role of a kind of service word denoting the beginning of the variant part. That is why at the end of the variant part you should not put end like a couple to case...of. (Since the variant part is always the last in the record, it is still followed by end, but only as a pair to record). Sentence selection key case...of is effectively ignored by the compiler: the only requirement for it in Object Pascal is that the key defines some standard or predeclared ordinal type.

    Field names must be unique within the record where they are declared, however, if the records contain record fields, that is, they are nested within each other, the names can be repeated at different nesting levels.

    1.2.3 Sets

    Sets - these are sets of the same type of objects logically related to each other. The nature of the relationships between objects is only implied by the programmer and is not controlled in any way by Object Pascal. The number of elements included in a set can vary from 0 to 256 (a set that does not contain elements is called empty). It is the inconstancy of the number of their elements that sets differ from arrays and records.

    Two sets are considered equivalent if and only if all their elements are the same, and the order of the elements in the set is indifferent. If all the elements of one set are also included in another, the first set is said to be included in the second. An empty set is included in any other set.

    The description of the set type is:

    <имя типа>= set of<базовый тип>;

    Here<имя типа>- correct identifier; set, of- reserved words (set, of);<базовый тип>- the basic type of set elements, which can be any ordinal type, except Word, Integer, Longint, Int64 .

    To define a set, the so-called set constructor is used: a list of specifications of the elements of the set, separated by commas; the list is surrounded by square brackets. Element specifications can be constants or expressions of a base type, or a range type of the same base type.

    The internal structure of the set is such that each of its elements is assigned one binary digit (one bit); if an element is included in a set, the corresponding bit has a value of 1, otherwise - 0. At the same time, the minimum unit of memory is one byte containing 8 bits, so the compiler allocated one byte to the sets, and as a result the power of each of them became equal 8 elements. The maximum capacity of the set is 256 elements. For such sets, the compiler allocates 16 adjacent bytes.

    And one more experiment: change the range of the base type to 1..256. Although the capacity of this type is 256 elements, when trying to compile a program the compiler will report the error: Sets may have at most 256 elements because the numbering of set elements starts from zero regardless of the lower bound declared in the program . The compiler allows the use as a base type of an integer range type with a minimum bound of 0 and a maximum of 255, or any enumerated type with no more than 256 elements (the maximum cardinality of an enumerated type is 65536 elements).

    1.3 Strings

    The following types are used for text processing in Object Pascal:

    short string shortString or string [n], where n<= 255;

    long string string ;

    wide line WideString ;

    null-terminal string pchar .

    What these types have in common is that each string is treated as a one-dimensional array of characters, the number of characters in which can change in a running program: for string [n], the string length changes from 0 to n, for string And pchar- from 0 to 2 GB.

    Standard Pascal uses only short strings String [n]. In memory, such a string is allocated n+i bytes, the first byte contains the current length of the string, and the characters themselves are located starting from the 2nd byte. Since the length of the string in this case is one byte, the maximum length of a short string cannot exceed 255 characters. The standard type is used to declare a short string of maximum length ShortString(equivalent String).

    Windows widely uses null-terminal strings, which are strings of characters delimited by the #o character. The maximum length of such a string is limited only by available memory and can be very large.

    A new type has been introduced in 32-bit versions of Delphi string, combining the conveniences of both types. When working with this type, memory is allocated as needed (dynamically) and is limited by the available memory available to the program.

    1.4 Pointers and dynamic memory

    1.4.1 Dynamic memory

    Dynamic memory- this is the PC RAM provided to the program during its operation. Dynamic data placement means the use of dynamic memory directly while the program is running. In contrast, static allocation is done by the Object Pascal compiler when the program is compiled. With dynamic placement, neither the type nor the amount of data to be placed is known in advance.

    1.4.2 Signposts

    PC RAM is a collection of cells for storing information - bytes, each of which has its own number. These numbers are called addresses, they allow you to access any byte of memory. Object Pascal provides the programmer with a flexible means of managing dynamic memory - so-called pointers. A pointer is a variable that contains the address of a byte of memory as its value. Using pointers, you can place any of the data types known in Object Pascal in dynamic memory. Only some of them ( Byte, Char, ShortInt, Boolean) occupy one byte in the internal representation, the rest - several adjacent ones. Therefore, the pointer actually addresses only the first byte of data.

    Typically, a pointer is associated with some data type. We will call such pointers typed. To declare a typed pointer, use the ^ icon, which is placed in front of the corresponding type.

    In Object Pascal, you can declare a pointer without having to associate it with any specific data type. This is done using the standard type pointer, For example:

    Pointers of this kind will be called untyped. Since untyped pointers are not associated with a specific type, they can be used to dynamically allocate data whose structure and type change as the program runs.

    As already mentioned, the values ​​of pointers are the addresses of variables in memory, so you would expect that the value of one pointer can be passed to another. Actually this is not true. In Object Pascal, you can only pass values ​​between pointers associated with the same data type.

    1.4.3 Allocating and freeing dynamic memory

    All dynamic memory in Object Pascal is treated as a continuous array of bytes, which is called a heap.

    Memory for any dynamically allocated variable is allocated by the New procedure. The parameter for calling this procedure is a typed pointer. As a result of the access, the pointer acquires a value corresponding to the address from which data can be placed. The value to which the pointer points, that is, the actual data allocated to the heap, is indicated by the ^ sign, which is placed immediately after the pointer. If there is no ^ sign after the pointer, then this means the address where the data is located. It makes sense to think again about what was just said: the value of any pointer is an address, and to indicate that we are not talking about the address, but about the data that is located at this address, a ^ is placed after the pointer (sometimes this is referred to as dereferencing pointer).

    Dynamically allocated data can be used anywhere in the program where it is valid for constants and variables of the appropriate type

    Dynamic memory can not only be taken from the heap, but also returned back. To do this, use the Dispose procedure. For example, operators

    Dispose(pJ);

    Dispose(pR);

    will return to the heap the memory that was previously assigned to the pJ and pR pointers (see above).

    Note that the Dispose (pPtr) procedure does not change the value of the pPtr pointer, but only returns the memory previously associated with this pointer to the heap. However, reapplying the procedure to a free pointer will result in a runtime error. The programmer can mark the freed pointer with the reserved word nil.

    1.5 Type aliases

    For any type you can declare as many aliases as you like. For example:

    TMyInteger = Integer;

    In the future, the alias can be used in the same way as the base type:

    Mylnt: TMyInteger;

    Mylnt:= 2*Round(pi);

    These kinds of aliases are usually used to improve the visibility of program code. However, in Object Pascal you can declare strongly typed aliases by adding the reserved word type before the name of the base type:

    TMyIntegerType = type Integer;

    MylntVar: TMyIntegerType;

    From the compiler's point of view, typed aliases are compatible with the base type in various kinds of expressions, but they actually declare a new data type, so they cannot be used as formal parameters for calling subroutines instead of the base type. If, for example, a procedure is declared

    function MylntFunc(APar: integer): Integer;

    then such an appeal to her

    MylntFunc(MylntVar)

    will be considered erroneous by the compiler.

    Strongly typed aliases force the compiler to generate run-time type information (RTTI). This information is usually used by the Delphi environment to support the functioning of various types of editors.

    Knowing and understanding data types is an integral part of programming.

    In this lesson we will learn about data types in the Turbo Pascal programming language.

    In the Pascal language, any objects, i.e. constants, variables, function values ​​or expressions are characterized by their types. A type defines the set of valid values ​​for an object, as well as the set of operations that are applicable to it. In addition, the type determines the format of the internal representation of data in the computer memory. In terms of object types, Pascal is a static language. This means that the type of an object, such as a variable, is determined when it is declared and cannot be changed later.

    Structure of data types in Pascal:

    Simple types of language
    Simple types include ordinal, real, string, and address (pointer) types. They all define the type of only one single value.

    Ordinal types characterized by the fact that each of them has a finite number of possible values, among which a linear order is established. Each value can be associated with a certain integer - its ordinal number.

    Integer types- denote sets of integers in different ranges. There are five integer types, differing in the range of valid values ​​and the size of RAM they occupy. Integer types are designated by identifiers: Byte, ShortInt, Word, Integer, LongInt; their characteristics are shown in the following table.

    Values ​​of integer types are written in the program in the usual way:
    123 4 -3 +345 -699
    The presence of a decimal point in notation of an integer is unacceptable. It would be an error to write an integer like this:
    123.0
    In addition to the usual decimal form of notation, it is possible to write integers in hexadecimal format using the prefix $, for example:
    $01AF $FF $1A $F0A1B
    The case of the letters A, B, ..., F does not matter.

    Valid operations:

    • - assignment;
    • - all arithmetic: +, - ,*, /, div, mod (with ordinary division [/] the result is real!);
    • - comparison<, >, >=, <=, <>, =.
    Boolean type- consists of only two values: False (false) and True (true). The words False and True are defined in the language and are, in fact, logical constants. The case of letters in their writing is unimportant: FALSE = false. Values ​​of this type are the result of evaluation of conditional and logical expressions and participate in all kinds of conditional operators of the language.
    Valid operations:
    • - assignment;
    • - comparison:<, >, >=, <=, <>, =;
    • - logical operations: NOT, OR, AND, XOR
    Character type (Char)- this is a data type consisting of one character (sign, letter, code). A Char value can be any character from the ASCII character set. If a symbol has a graphical representation, then in the program it is written enclosed in single quotes (apostrophes), for example:
    "w" "s" "." "*" " "-(space)
    To represent the apostrophe itself, its image is doubled: """".
    If the character does not have a graphical representation, for example, a tab character or a carriage return character, then you can use an equivalent form of writing the character value, consisting of the prefix # and the ASCII code of the character:
    #9 #32 #13
    Valid operations:
    • - assignment;
    • - comparison:<, >, >=, <=, <>, =. The largest character is the one with the larger ASCII number.
    String type (String, String[n])- This data type defines sequences of characters - strings. The n parameter specifies the maximum number of characters per line. If not specified, n=255 is assumed. A value of type “string” in a program is written as a sequence of characters enclosed in single quotes (apostrophes), for example
    "This is a string"
    "1234" is also a string, not a number
    "" - empty line

    Valid operations:
    • - assignment;
    • - addition (concatenation, merger); for example, S:= "Winter"+" "+"has arrived!";
    • - comparison:<, >, >=, <=, <>, =. Strings are considered equal if they are the same length and are character-by-character equivalent.
    Real types- denote sets of real numbers in different ranges. There are five real types, differing in the range of acceptable values ​​and the size of the occupied RAM. Real types are designated by identifiers: Real, Single, Double, Extended, Comp; their characteristics are shown in the following table.

    Comp type although classified as a real type, it is actually an integer with a very huge range of values.
    Values ​​of real types can be written in a program in several ways:
    1.456 0.000134 -120.0 65432
    +345 0 -45 127E+12
    -1.5E-5 -1.6E+12 5E4 0.002E-6

    It would be a mistake to write a real number like this:
    .5 (correct 0.5)
    12. (correctly 12.0 or 12)

    A real number in floating point form (scientific form) is written as a pair
    <мантисса>E<порядок>
    This designation is understood as “the mantissa multiplied by ten to a power equal to the order.” For example,
    -1.6E+12 corresponds to -1.6 1012

    Valid operations:
    - assignment;
    - all arithmetic: +, - ,*, /;
    - comparison:<, >, >=, <=, <>, =.

    When comparing real numbers, you should remember that due to the inaccuracy of their representation in computer memory (due to the inevitability of rounding), you should avoid trying to determine the strict equality of two real values. There is a chance that the equality will be false, even if in fact it is not.

    A range or (restricted type) is not a predefined language type (such as Integer or Char) and therefore has no identifier associated with it. This type is user input. Using it we can define a new type that will contain values ​​only from a limited subrange of some base type. The base type can only be an integer type, a Char type (character), and any of the enumeration types introduced by the programmer.

    To introduce a new type - a range - you need to indicate in the TYPE type description block the name of the entered type and the boundaries of the range through the special range symbol ".." (two dots in a row):
    TYPE
    Century = 1..21; (integer type subrange)
    CapsLetters = "A"."Z"; (subrange of type Char)

    Structured Language Types

    Structured types include: array, record, set, file, etc. All of them define the type (or types) of some data structure.

    Array- an ordered structure of data of the same type that stores them sequentially. The array must have dimensions that determine how many elements are stored in the structure. Any element in an array can be reached by its index.

    The array type is determined by the construction:
    Array [range] of ElementType;

    The range in square brackets indicates the index values ​​of the first and last element in the structure. Examples of declarations of types and variables:

    TYPE Vector = array of Real; VAR V1: Vector;
    V2: array of Byte;

    Here the variable V1 is defined using the Vector type described above; the type of variable V2 is constructed directly at the stage of its description.
    As an array element type, you can also specify an array, thereby forming multidimensional structures. For example, a description of a two-dimensional structure (matrix) will look like this:
    VAR M1: array of array of Byte; The same thing can be written much more compactly: VAR M2: array of Byte;

    An array element is accessed by specifying its index, for example:

    Writeln(V1); (displaying the first element of array V1) readln(M2); (inputting the third element of the second row of matrix M2)
    This concludes the lesson on data types, the text was almost completely copied and pasted (the link will be below), because I don’t see the point in telling this material in my own words. If the difference between data types is at least a little clear, then this is already good.

    mob_info