12.2.3 Auto Variable Allocation and Access
This section discusses allocation of auto
variables
(those with automatic storage duration). This also includes function parameter
variables, which behave like auto
variables, as well as temporary
variables defined by the compiler.
The auto
(short for automatic) variables are the
default type of local variable. Unless explicitly declared to be
static
, a local variable will be made auto
. The
auto
keyword may be used if desired.
auto variables, as their name suggests, automatically come into existence when a block is executed and then disappear once the block exits. Since they are not in existence for the entire duration of the program, there is the possibility to reclaim memory they use when the variables are not in existence and allocate it to other variables in the program.
Typically such variables are stored on some sort of a data stack, which can easily allocate then deallocate memory as required by each function. The stack is discussed in below in Software Stack.
The the standard qualifiers: const
and
volatile
may both be used with auto
variables and
these do not affect how they are positioned in memory. This implies that a local
const
-qualified object is still an auto
object and
as such, will be allocated memory on the stack, not in the program memory like with
non-auto
const
objects.