ComputersProgramming

What are the types of data in Pascal?

When programming in Pascal, you need to select the Pascal program data types. It is important for the programmer to understand that 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.

All data types in Pascal are divided into two groups: simple and structured. For each type of data, a number of bytes are allocated. Simple types include: integer types (byte, integer, etc.), real types (real, single, etc.), logical type (boolean), character type (char), enumerated and interval type. All of them, with the exception of real types, are ordinal types and are characterized by having a limited ordered set of values. For example, a variable of type byte can take values in the range from 0 to 255, inclusive. These types of data in Pascal allow you to use the Pred function (computes the previous value) and Succ (calculates the subsequent value), Low (calculate the smallest value of the type) and High (calculates the largest value of the type), Ord (calculates the sequence number of the current value of the variable).

A variable of a simple type has only one data as its value, i.e. A single integer, a fractional number, or one character. Variables that have simple data types in Pascal must be described in the Var section (short for Variables).

A variable in a Pascal program is considered fully qualified if it has a name (identifier), type, and initial value. The variable name is used when accessing it by means of an operator. The data type defines the range of the 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 the RAM. Therefore, when solving a problem, one should tend to reduce the number of variables and rational selection of their types.

Structured types are an ordered set of simple variables. These include: arrays, sets of, strings, files, and records. Structured data types in Pascal are described in the type section.

An array, the most common structured type, is used when you want to store and process an ordered set of variables of the same type (of any simple type). Arrays can be one-dimensional, two-dimensional, multidimensional. An example of a one-dimensional array can be a list of students in the class journal, sorted alphabetically, where each student has a unique serial number. An example of a two-dimensional array is the location of places in the auditorium of the cinema (each location is determined by two dimensions - the number of the row and the number of the place).

The elements of the set are unordered, unlike the array, and the number of elements is limited to 255. A string is an ordered set of symbols and is very similar to an array, but only characters can be line items.

A file is the same array, but the number of elements in it can vary during the execution of the program. A record is a collection of different types of data.

Learning to apply data types in Pascal, you can implement fairly complex and interesting tasks.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.delachieve.com. Theme powered by WordPress.