In C, an object has a storage duration, which determine its lifetime. There are four storage durations: static, thread, automatic, and allocated. 1

storage duration is the property of an object. As functions are not objects in C, they do not have storage duration.

The lifetime of an object is “the duration of program execution during which storage is guaranteed to be reserved for it.” During the lifetime of the object, it exists, has constant address, and retains its last-stored value. Accessing an object outside its lifetime is undefined behavior. 1

Scope and lifetime do not always correlate. Only for variables with automatic storage duration is the lifetime of the underlying object tied to the scope of the variable.

Variables in block scope without storage specifiers have automatic storage duration.

All variables declared globally or with static and extern storage specifiers have static storage duration, whose lifetime extends to the entirety of the program.

See Also

Footnotes

  1. C23 Standard Draft 6.2.4 2