A variable is a location in memory that holds a value of a specified type that can vary over the life of the variable, identified by its name. When the variable is defined with both a type and an identifier, its life begins. It can hold the same value throughout its life or it can be modified or overwritten with a new value of that type. The variable's life ends—that is, the memory it identifies is deallocated—when the block in which it was declared ends. We'll talk more about variable lifetimes in Chapter 25, Understanding Scope.
So, a variable is a memory location with an identifier (name) associated with a type that contains a value. The following three components are essential:
- A unique identifier or name
- A type
- A value
The variable should always have some known starting value, even if it is 0; this is called initialization. If we don't give the variable an initial...