Declaration of Storage Class
Variables in C have not only the data type but also storage class that provides information
about their location, visibility, and scope of that variable. The storage class divides the
portion of the program within which the variables are recognized.
Following types of storage classes available in C language.
Variables in C have not only the data type but also storage class that provides information
about their location, visibility, and scope of that variable. The storage class divides the
portion of the program within which the variables are recognized.
Following types of storage classes available in C language.
Automatic storage classes
1) auto: It is a local variable known only to the function in which it is declared. Auto is the
default storage class that is accessible within a block where it is declared.
Storage: Memory
Default Initial Value : Garbage Value
Scope : Local Variable
Life : Till Control remains within the Block in which variable is defined.
Example
main()
{
auto int i=5;
printf(“%d”,i) ;
}
Static storage classes
2) Static :Local variable which exists and retains its value even after the control is transferred to
the calling function. Generally it is used in functions so whenever functions call multiple
times then static variable stored it hold value in it. It is initialize first time only When it is
declared.
Storage: Memory
Default Initial Value : zero
Scope : Local Variable
Life : it hold’s the value when It come-out From The Function.
Example
main()
{
static int i=5;
printf(“%d”,i) ;
}
Extern storage classes
3) Extern: It is default storage class of all global variables as well all functions.Global variable
is accessible in all the functions blocks of the program. Generally it is declared out side of
function block.
Storage: Memory
Default Initial Value : zero
Scope : Global Variable
Life : it hold the value until program execution does not come to end.
example
extern int i=10; //extern variable
main(){
printf("%d",i);
return 0;
}
Register storage classes
4) register: The value of this type of variable is stored in register so it can be accessible very
fast that is the main advantage of this variable but some limited registers are available during
the execution process.
General syntax to declare variable with storage class is given as under.
<Storageclassname>data type<variablename>;
Storage: CPU Register
Default Initial Value : Garbage Value
Scope : Local Variable
Life : Till Control remains within the Block in which variable is defined
0 Comments