Program variables have a storage class in addition to a data type. Storage classes are important in C++ for several reasons. One, they tell the compiler how to create and release variables and where to place them in the run-time environment (stack, data area, or CPU registers). Two, storage class specifiers affect the initial values and the scope of variables. This section reviews the storage class specifiers auto, static, register, extern, and mutable.
The default storage class specifier auto (short for automatic) allocates memory for variables from the run-time stack. The definition
auto int num;
for example, compiles in C++, although the keyword auto is optional and seldom used. Automatic definitions appear inside ...