Address | Value |
0 | 27 |
1 | 255 |
2 | 0 |
3 | -128 |
4 | 127 |
⋮ | |
4,294,967,296 | 73 |
You can think of Computer Memory as a big table or as rows (and 2 columns) of a spreadsheet.
A Variable in Math
Favorite variable names?
x y z
2x - 9 = 27
y = 2x - 9
A Variable in Programming
a name for a location in memory
speed = 85
think of it as a box with a label, where the box can store numbers and other types of data
speed
85
Variable
a name for a location in memory that stores data
speed
stop
firstName
assign the value on the right side to the name on the left
speedLimit = speed - 25
does not mean equals but assign
speedLimit
60
speed
85
=
Not a valid math equation!!!
speed = speed - 25
often reuse the same box (i.e. name) for the new value
before assignment
after assignment
speed
85
60
Use meaningful variable names
u = 4
p = 2.5
x = 0.1
T = u * p + (u* p * x)
units = 4
price = 2.5
taxRate = 0.1
totalPrice = units * price + (units * price * taxRate)