Home >>C Tutorial >Storage classes in C

Storage classes in C

Storage classes in C

Storage classes in C generally represent the visibility and the location of a variable. It basically tells the programmer that from which part of the code he/she can access a variable.

In order to describe the following mentioned things, a storage class in C language is used:

  • The initialized value of a variable.
  • Permission to access a variable
  • The variable scope.
  • The storage location of the variable.
  • A variable's lifetime.

From the above mentioned facts it is clear that a storage class is basically used to represent the information about a variable.

Please note that a variable is generally not only associated with a data type and its value but it is also associated with a storage class.

There are basically four types of standard storage class in C language that is depicted below:

  • Auto
  • Extern
  • Static
  • Register

Here is an example of the Storage classes in C that is mentioned below:

#include <stdio.h>  
int main()  
{  
int x =100,i;   
printf("%d ",++x);//Here scope of a variable is  is 101  
{  
	int x = 15;   
	for (i=0;i<3;i++)  
	{  
	printf("%d ",x); // this will print 15 3 times
	}  
}  
printf("%d ",x);//Here scope of a variable ended Since output is 101
}  
Output :101 15 15 15 101

No Sidebar ads