Storage Class
A storage class is an attribute that tells us where the variable would be stored,
what will be the initial value of the variable if no value is assigned to that variable,
life time of the variable and scope of the variable.
Scope:- Scope of variable tells compiler the visibility of variable in the block
There are four storage classes in C:
Automatic storage class:
keyword - ‘auto’.
variable declared stored in the memory.
Default - garbage value.
Scope - local to the block in which the variable is defined.
Variable is alive till the control remains within the block in which the variable id defined.
Example
Register storage class:
keyword -‘register’.
Variable declared stored in the CPU register.
Default - garbage value.
Scope of variable - local to the block
Example
Static storage class:
keyword - ‘static’.
variable declared stored in the memory.
Default - zero.
Scope- local to the block in which the variable is defined.
Life of variable persists between different function calls.
Example
External storage class:
keyword - ‘extern’.
Variable declared stored in the memory.
Default - zero.
Scope - global.
-Variable is alive as long as the program’s execution doesn’t come to an end.
-External variable can be declared outside all the functions or inside function using ‘extern’ keyword.
Example
@naymyoaung
follow and vote for more chapter