Module: VARIABLES. OUTPUT FORMATS


Problem

1/5

Variables

Theory Click to read/hide

Variables
A variable is a cell in computer memory that has a name and stores some value corresponding to the 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 int (from English integer – whole), occupy 4 bytes in memory;
- real variables that can have a fractional part (type float – from English floating point – floating point) occupy 4 bytes in memory;
- 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.
Also, if necessary, you can assign initial values ​​to it. 

Let's take a program as an example:
using System;
class Program {
    static void Main()
    {
        int a = 6, b; // declared two variables of integer type, in variable a immediately saved the value 6.
  // Variable b was not initialized;
                      // what will be in memory in this case, we do not know.
    }
}


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.

Problem

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