Storage Duration

Storage duration determines how long storage for an object exists. An object has either static storage duration or automatic storage duration depending on its declaration. Descriptions of each follow:

Static storage Is allocated at initialization and remains available until the program ends. Objects have static storage duration if they:
  • Have file scope
  • Have external or internal linkage OR
  • Contain the static storage class specifier.
Automatic storage Is allocated and removed according to the scope of the identifier. Objects have automatic storage duration if they are:
  • Parameters in a function definition.
  • Declared at block scope and do not have any storage class specifier. OR
  • Declared at block scope and have the register or auto storage class specifier.

For example, storage for an object declared at block scope is allocated when the identifier is declared and removed when the closing brace (}) is reached.

Note: Objects can also have heap storage duration. Heap objects are created at runtime and storage is allocated for them by calling a function such as malloc().



Scope of Identifier Visibility
Program Linkage Between Identifiers
Name Spaces