Storage classes in C
Appearance
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 |