< previous page page_28 next page >

Page 28
cubby holes, all lined up in a long row. Each cubby holeor memory locationis numbered sequentially. These numbers are known as memory addresses.
Variables not only have addresses, they have names. For example, you might create a variable named myAge. Your variable is a label on one of these cubby holes so that you can find it easily, without knowing its actual memory address.
Figure 3.1 is a schematic representation of this idea. As you can see from the figure, we've declared a variable named myVariable. myVariable starts at memory address 103.
10905-0028a.gif
FIGURE 3.1
A schematic representation of memory.
New Term: RAM is Random Access Memory. When you run your program, it is loaded into RAM from the disk file. All variables are created in RAM as well. When programmers talk of memory, it is usually RAM to which they are referring.

Setting Aside Memory
New Term: When you define a variable in C++, you must tell the compiler not only what its name is, but also what kind of information it will hold: integer, character, and so forth. This is the variable's type. The type of the variable tells the compiler how much room to set aside in memory to hold the variable's value.
Each cubby is one byte large. If the type of variable you create is two bytes in size, it needs two bytes of memory, or two cubbies. The type of the variable (for example, int) tells the compiler how much memory (how many cubby holes) to set aside for the variable.
Because computers use bits and bytes to represent values, and because memory is measured in bytes, it is important that you understand and are comfortable with these concepts.
Size of Integers.
New Term: A char variable (used to hold characters) is most often one byte long. A short int is two bytes on most computers; a long int is usually four bytes, and an

 
< previous page page_28 next page >

If you like this book, buy it!