Skip to content
UPEEC

Storage Classes

auto, static, extern and register control a variable's lifetime and visibility.

Intermediate
Comments 0
  • auto — the default for local variables: created when the block starts, destroyed when it ends.
  • static (inside a function) — keeps its value between calls:
int counter(void) {
    static int count = 0;   // initialised once
    return ++count;
}
  • static (at file level) — visible only inside that .c file.
  • extern — declares a global variable defined in another file.
  • register — a hint to keep a variable in a CPU register (modern compilers ignore it).

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.