19D. The Memory and Memory Addresses

The main memory

The main memory (or simply the memory) is where variables and other information are stored while a program runs. Sometimes it is called the RAM, for random-access memory. From the perspective of a program, the computer's memory is a collection of bytes, each with an integer address. A program can fetch the current contents of the byte at a given memory address and it can store a value into a byte of memory.

A byte is just 8 bits, and most data items are larger than that. For example, a value of type int is usually 32 bits, so it occupies 4 bytes. A program refers to a block of memory using the address of the first byte in the block. For example, an integer stored in bytes 1000-1003 has address 1000.

Exercises

  1. What sort of thing is stored in a variable of type long*? Answer

  2. How can you declare two variables p and q, each of type int*, in a single declaration? Answer