Storage Duration

From C

Jump to: navigation, search

The storage duration of an object determines its lifetime. There are three storage durations: static, auto, and allocated. Objects defined at file scope have static storage duration. Objects defined with the static keyword have static storage duration. String literals have static storage duration. All other object definitions have automatic storage duration. These are local variables.

Allocated storage applies to objects obtained via a call to malloc(), calloc(), or realloc().

Objects with static storage duration live for the lifetime of the program.

Objects with automatic storage duration live for the lifetime of the block in which they execute.

Objects with allocated storage duration live until they are destroyed by a call to free().

For more information, see this fairly comprehensive Usenet article by Chris Torek about linkage, scope, duration, and "definition-ness" (google) (usenet).


Category Language, Category Stub

Personal tools