c Storage Classes

A Storage class in C represents the scope of a variable within the program. The storage classes in C are discussed below:

 

Storage Classes Storage Place Default Value Scope Life-time Features
auto RAM Garbage Local Within function Default storage class.
extern RAM 0 Global Till the end of main program Visible to all the programs.
static RAM 0 Local Till the end of main program Retains value between multiple functions call.
register Register Garbage Local Within function Faster access than other variables.

 

Example:

#include<stdio.h>  
void demo()
{    
static int i=0;
register int j=0;
auto int k=0;
i++;    
j++;
k++;
 
printf("i = %d\n", i);    
printf("j = %d\n", j);    
printf("k = %d\n", k);    
}  
 
void main()
{    
demo();   
printf ("\n");
demo();   
printf ("\n");
demo();    
}

Output

i = 1
j = 1
k = 1
 
i = 2
j = 1
k = 1
 
i = 3
j = 1
k = 1
Please follow and like us:
Content Protection by DMCA.com