Previous: 14.1 Storage Classes
Up: 14.1 Storage Classes
Next: 14.1.2 Register Variables
Previous Page: 14.1 Storage Classes
Next Page: 14.1.2 Register Variables
We have already discussed automatic variables. They are declared at the start of a block. Memory is allocated automatically upon entry to a block and freed automatically upon exit from the block. The scope of automatic variables is local to the block in which they are declared, including any blocks nested within that block. For these reasons, they are also called local variables. No block outside the defining block may have direct access to automatic variables, i.e. by name. Of course, they may be accessed indirectly by other blocks and/or functions using pointers.
Automatic variables may be specified upon declaration to be of storage class auto. However, it is not required; by default, storage class within a block is auto. Automatic variables declared with initializers are initialized each time the block in which they are declared is entered.