3.4. Storage Classes

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.

auto

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 ...

Get Navigating C++ and Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.