Jump to content

Storage classes in C

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 195.230.103.1 (talk) at 10:51, 30 March 2011. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

To fully define a variable, it is needed to mention both the "type"(data type) and the "storage class". If a storage class is not specified in declaration of a variable, the compiler will assume a storage class depending upon the context in which the variable is used.

The storage classes will tell: a) Where the variable would be stored b) Default initial value of the variable c) Scope of the variable d) Life of the variable

There are 4 storage classes in C.

Storage Classes Storage Default Initial Value Scope Life
Automatic Memory Garbage value Local to the block Till the control remains in block
Register CPU Registers Garbage Value Local to the block Till the control remains in block
Static Memory Zero Local to the block Between the function calls
Extern Memory Zero Global Till the end of execution