You are on page 1of 3

Storage classes

Automatic Storage class


1)keyword auto(deprecate)
2)local variables belongs to auto variable
3)local variable cannot be declared globally
4)initial value is garbage
5)scope and lifetime is within the block/within the function
6)storage is stack section
7)NO linkage
8)local variable is having NO linkage
9)bydefault storage class

There are 3 types of linkage


1)NO lINKAGE
2)INTERNAL LINKAGE
3)EXTERNAL LINKAGE

static storage class


1)The variable declared with static keyword is called as static variable
2)static variable can be declared globally as well as locally
3)initial value is 0
4)stored on datasection

#include <stdio.h>
static int y;//global static variable
void main()
{
static int x;//local static variable
printf("%d %d",x,y);
show();
getchar();
getchar();
}
void show()
{
printf("%d %d",x,y);
}
//scope of x variable is within the block /within the function
//scope of y variable is thru out the program
//lifetime of static variable x,y is thru out the program

Difference between local variable and static variable


local variable
1)the variable declared within the paraenthesis of a function or a block
is called as local variable
2)stored on stack section
3)inital value is garbage
4)lifetime is within the block/within the function
5)
#include <stdio.h>
void show();
void main()
{
show();
show();
show();
getchar();
getchar();
}
void show()
{
int x=0;
printf("%d",x);//000
x++;//1
}
whenever the function is called,new memory is always allocated to local
variable and this memory exist till the scope of that function
6)reinitilization takes place for local variable

-----------------------------
#include <stdio.h>
static int y=10;//global static variable
void main()
{
static int y=20;//local static variable
printf("%d",y);//20
getchar();
getchar();
}

-----------------------------------------------------
Register storage class
1)keyword-->register
2)The variable declared with register keyword is called as register variable
3)register variable should not be declare globally
4)initial value is garbage
5)scope and lifetime will be within the block/within the function
6)NO linkage
7)stored on registers(AX,BX,CX----)
8)to access small amount of data at the faster rate
9)we cannot use & on register variable
10)registers are very limited,if sufficient memory is not availabe then
data will be shifted to PS.

-----------------------------------------------------------------------
Extern storage class/global variable
1)the variable declare with extern keyword is called as extern variable
2)global variable belongs to extern variable
3)initial value is 0
4)storage is data section
5)keyword-->extern
6)lifetime-->thru out the program
7)scope-->across the file
8)linkage-->external linkage

linkage-->association of a variable with the file

----------------------------------------------------------------

You might also like