Module: VARIABLES. OUTPUT FORMATS


Problem

1/6

Variables

Theory Click to read/hide

Variables
A computer would not be needed if it did not have the ability to store various information in its memory and be able to process information of the same type using the same algorithms. 
In order to create more interesting programs, one must learn how to store information in the computer's memory. At the same time, we need to learn how to somehow access the memory cells of the computer. 
In programming, as in life, in order to refer to any part of the computer's memory, it occurs by name. Using this name, you can both read information and write it there.
 
A variable is a location in computer memory that has a name and stores some value corresponding to type.

The word "variable" tells us that its value can change during program execution.  When a new variable value is saved, the old one is erased.


For a computer, all information is data in its memory - sets of zeros and ones (to put it simply, any information in a computer is just numbers, and it processes them in the same way). However, we know that integers and fractional numbers work differently. Therefore, each programming language has different types of data, which are processed using different methods.

For example,
integer variables – type integer (from English integer – whole), occupy 2 bytes in memory;
real variables that can have a fractional part (type real – from English real numbers - real numbers), occupy 6 bytes in memory;< br /> - characters (type char – from English character – symbol), occupy 1 byte in memory.

Let's try to add some variable to our program.
Before using a variable, you need to tell the computer to allocate space in memory for it. To do this, you need to declare a variable, that is, specify what type of value it will store, and give it a name. To do this, at the beginning of the program you need to write:

var <comma-separated variable names>: <the type of these variables>;
       <names of variables of another type separated by commas>: <the type of these variables>; 

 
Example
var a, b: integer; // declared two variables a and b of integer type. Until we initialize them so we don't know what's in memory. begin a := 6; // variable a was assigned the value 6 end.

Problem

On the third line, declare a variable a of an integer type with an initial value of 7.