Definition
of a ‘Variable’
Different languages
may differ slightly,
but the concept is
the same as shown here.
A “variable” is a letter or word that identifies a
place
in the computer’s memory where data is stored.
A variable can be used on the left side of the equal
sign
in an assignment statement to store information
to be used later in the program.
A variable can be used on the right side of the equal
sign
in an expression to retrieve information
that was previously stored in the computer’s memory.
However, sometimes expressions can be more complex
and there is some math to do, like 10 + 15.
Now we have to “do the math” and figure it out
:
We add the two numbers in the expression to get one
answer : 25.
Expressions always “resolve” into a single
value.
Sometimes the math is a little harder to do, like the
expression (7 + 3) * (2 + 3) ,
It may be convenient to think of variables as a way
to substitute a name for a value.
For example :
|
Program Line |
What does the program line do ?
|
|
|
|
Price = 100 |
The program assigns the value 100 |
||
|
Tax = .0775 |
The program assigns the value .0775 |
||
|
Total = Price * Tax |
The program looks up the values called Price * Tax The program then assigns the calculated value |
||
|
PRINT Price , Tax, Total |
Program looks up values stored in Price
, Tax and Total, and displays or prints them. |
||