Storage class in C, Automatic storage, Static storage, File scope, Block space
Storage class specifiers
Storage duration – how long an object exists in memory
Scope – where object can be referenced in program
Linkage – specifies the files in which an identifier is known (more in Chapter
Automatic storage
Object created and destroyed within its block
auto: default for local variables
auto double x, y;
register: tries to put variable into high-speed registers
Can only be used for automatic variables
register int counter = 1;
Static storage
Variables exist for entire program execution
Default value of zero
static: local variables defined in functions.
Keep value after function ends
Only known in their own function
extern: default for global variables and functions
Known in any function
File scope
Identifier defined outside function, known in all functions
Used for global variables, function definitions, function prototypes
Function scope
Can only be referenced inside a function body
Used only for labels (start:, case: , etc.)
Block scope
Identifier declared inside a block
Block scope begins at declaration, ends at right brace
Used for variables, function parameters (local variables of function)
Outer blocks "hidden" from inner blocks if there is a variable with the same name in the inner block
Function prototype scope
Used for identifiers in parameter list