< previous page page_57 next page >

Page 57
be associated with the identifier. We don't have to know the actual address of the memory location because the computer automatically keeps track of it for us.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Declaration A statement that associates an identifier with a data object, a function, or a data type so that the programmer can refer to that item by name.
Suppose that when we mailed a letter, we just had to put a name on it and the post office would look up the address. Of course, everybody in the world would have to have a different name; otherwise the post office wouldn't be able to figure out whose address was whose. The same is true in C++. Each identifier can represent just one thing (except under special circumstances, which we talk about in Chapters 7 and 8). Every identifier you use in a program must be different from all others.
Constants and variables are collectively called data objects. Both data objects and the actual instructions in a program are stored in various memory locations. You have seen that a group of instructionsa functioncan be given a name. Later on, you'll see that a name also can be associated with a programmer-defined data type, a data type that is not predefined in the C++ language.
In C++ you must declare every identifier before it is used. This allows the compiler to verify that the use of the identifier is consistent with what it was declared to be. If you declare an identifier to be a constant and later try to change its value, the compiler detects this inconsistency and issues an error message.
There is a different form of declaration statement for each kind of data object, function, or data type in C++. The forms of declaration for variables and constants are introduced here; others are covered in later chapters.
Variables
A program operates on data. Data isstored in memory. While a program is executing, different values may be stored in the same memory location at different times. This kind of memory location is called a variable, and its contents are the variable value. The symbolic name that we associate with a memory location is the variable name or variable identifier (see Figure 2-2). In practice, we often refer to the variable name as the variable.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Variable A location in memory, referenced by an identifier, in which a data value that can be changed is stored.

 
< previous page page_57 next page >