1 of 8

2 of 8

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.

3 of 8

A Variable in Math

Favorite variable names?

x y z

2x - 9 = 27

y = 2x - 9

  • one correct value
  • many values
  • (in)dependent

4 of 8

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

5 of 8

Variable

a name for a location in memory that stores data

speed

stop

firstName

6 of 8

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

=

7 of 8

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

8 of 8

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)