About Lesson
Storage Classes in C
Storage Class
auto
static
register
extern
by default when we declare a variable belong to auto storage class
static int x;
C
#include<STDIO.H>
void msg();
int main()
{
msg();
msg();
msg();
}
void msg()
{
static int x=1;
printf("\nX=%d",x);
x++;
}
/*
X=1
X=1
X=1
Static variable preserve itsself last value in multiple function call
*/
Class | Location | Default Value | Scope | Life |
auto | RAM | Garbage | inside block | inside block |
static | RAM | 0 | inside block | until end of program |
register | CPU REGISTER | Garbage | inside block | inside block |
extern | RAM | 0 | whole program (Global) | until end of program |