Professional Documents
Culture Documents
( Characteristics of Variable )
i.e.
automatic .
II. Initial value of Variable III. Scope of Variable IV. Lifetime of Variable i.e. how long variable exists.
auto int a ,b ;
Storage Class Data Type Variable
Four Type of Storage Class in C Language : Automatic Storage Class ( Local Variables ) Register Storage Class Static Storage Class External Storage Class
auto int a ;
Characteristics
Storage Initial Value
Meaning
Memory Garbage Value i.e. An Unpredictable Value.
Scope or Visibility
Life Time
Local or Visible in the Block or function in which it is declared. It retains its value till it is in the block in which it is declared.
int i = 0 ;
printf ( \n\n Value of I ..%d,i ) ; i++;
ck ( ) ;
ck ( ) ; ck ( ) ; }
Output
0 0
getch( ) ;
}
Meaning
C P U Registers Garbage Value Local to the Block in which it is declared It retains its value till the control remains in the block
Use of scanf with register store class variable is invalid Prgram give error because register is not associated with any memory address. #include<stdio.h> int main() { register int num; //register variable its scope lies with in the main //function and can not use with scanf clrscr(); scanf("%d",&num); // Error is must take address of memory location getch(); return 0; }
value even after the execution of the function in which it is declared, then
this storage class is used . It is declared as follow :-
static int a ;
Characteristics
Storage Initial Value
Meaning
Memory Zero ( 0 )
Scope or Visibility
Life Time
static int i = 0 ;
printf ( \n\n Value of I ..%d,i ) ; i++; } Output
ck ( ) ;
ck ( ) ; ck ( ) ;
getch( ) ;
}
0
1 2
extern int a ;
Characteristics
Storage Initial Value Scope or Visibility
Meaning
Memory Zero ( 0 ) Global ( Visible in all the Program )
Life Time
a = a + 10 ;
printf ( \n\n Value of a ..%d,a ) ; } Output 5 20
void main( )
{ int a = 5 ; printf ( %d , a) ;
ck ( ) ;
getch ( ) ;}
#include<stdio.h> #include<conio.h> int x=21; int main() { int y; clrscr(); printf("%d \t %d",x,y); getch(); return 0;
#include<stdio.h> #include<conio.h> int x=21; int main() { Extern int y; //external variable declare clrscr(); printf("%d \t %d",x,y); getch(); return 0;
} int y=31;