Introduction To Data Types
Introduction To Data Types
Static types
Almost all types of data are static, the exception is pointers and they will not be addressed due to their complexity.
That a data type is static means that the size it occupies in memory cannot vary during execution.
program. That is, oncedeclareda variable of a determined type is assigned a fixed piece of memory, and this piece
it cannot be increased or decreased.
Dynamic types
Within this category only the pointer type enters. This type allows you to have greater control over memory management in.
your programs. With them, you can manage the size of your variables at runtime, that is, when the program is running
running.
Pointers may be the most complex concept when learning a programming language, especially if it is the first one.
What you learn. Because of this, we will not address it. Furthermore, languages that are very trendy (for example, Java) do not allow for
programmer work with pointers.
Simple types
As their name indicates, they are the basic types in Pascal. They are the simplest and easiest to learn. For all this, they will be in
those of us who focus.
The most basic simple types are: whole, logical, characteryreal. And most programming languages support them, right?
as happens with structures that can vary from one language to another.
Structured types
While a variable of a simple type only references a single element, structured types refer to collections of elements.
The collections of elements that appear when talking about structured types are very varied: we have ordered collections that
they are represented by the array type, unordered collections by the set type, and even collections that contain others
types, are the so-called records.
Ordinal types
Among the simple types, the ordinals are the most abundant. A type is said to be ordinal because the set of values
that represents can be counted, that is, we can establish a one-to-one relationship between its elements and the set of the
natural numbers.
Among the simple ordinal types, the most important are:
The integer type(integer)
The logical type(boolean)
The character type(character)
Non-ordinal types
Simplifying, we could reduce the non-ordinal simple types to the typereal. This type helps us declare variables that can
take values within the set of real numbers.
Unlike ordinal types, non-ordinal ones cannot be counted. A one-to-one relationship cannot be established between them and
the natural numbers. In other words, for a set to be considered ordinal, it must be possible to calculate the position, the
the previous element and the next one of any element of the set. What is the successor of 5.12? It will be 5.13, or 5.120, or 5.121, ...
The basic types that interest us
After looking at one of the possible classifications for data types, let's move on to those that interest us: the simple types.
We will really see the most basic simple types, which are: integer, boolean, characteryreal. Additionally, we will also talk about a
a little about character strings, the so-calledstrings.
Note: below will only be commented on what each type is, its declaration will not be explained, you can see this if you go tothesection
corresponding.
type
integer
var
i : tCounter;
n : integer;
begin
n := 10; (* we assign a value to the maximum *)
i := 1; (* we assign a value to the counter *)
type
tLogico = boolean;
var
it rains: tLogical; (* if it rains or not *)
boolean; whether I find the umbrella or not
*)
begin
(* here the values of 'it rains' would be determined and
umbrella
if it rains and (not umbrella) then
I stay at home
else
I'm going to take a walk
end.
const
pi = 3.1416;
type
tArea = real;
var
A : tArea; (* area *)
R : real; (* radio *)
begin
R := 4.50;
A := pi * R * R; (We calculate the area)
type
tName = string[10]; (* can store 10 characters
*)
var
name tName; (* variable to store the
name *)
char; (** character to contain the
NIF letter *
begin
name Me
L