What is a Variable?
Variables are memory cells that are addressed via a name which is an identifier. The identifiers can be of any length, but the first character must be a letter and spaces are not allowed. The value of the variable is stored in the memory cell. Variables have an assigned data type and can be thought of as a box. The identifier of the variable is on the front of the box and there is a slip of paper in the box with the value of the variable. The size of the box is different depending on the data type, i.e. different numbers of memory cells are reserved.
The value of a variable changes during the execution of the program. Example: Our robot should take 3 cars at a time. At the beginning there are 3 when he has taken the first one, only 2, then only 1, then 0. When he has packed them and comes back, there are 3 again, etc. We remember how many cars he should take in a variable: At the beginning there are 3. We write the instruction
Creating a variable is called declaring. The first time a value is assigned to a variable, it is called initializing. The declaration and initialization can be done in a single step, or more. A variable must be declared and initialized before it can be used.