Search Placementyogi.com
 

Storage Classes in C

Storage classes in C tells the compiler - 

  • where and how to store variable in memory.
  • what would be initial default value of variable.
  • what would be scope of variable (i.e what are the functions to which it's value is accessible).
  • what would be life cycle of variable (i.e how long the variable would exist) .

For example consider following program

#include<stdio.h>
int a;
int main()
{
  int b;
  static int c;

  printf("a=%d b=%d c=%d",a,b,c);

}

In above program what would be default value assigned to a, b and c by compiler? Compiler assign default values based on their storage classes. Here output of program would be a=0, b=some garbage value, c=0. Don't worry we will discuss in details about default values assignment. First lets discuss about types of storage classes in C.   


There are four storage classes in C.

  1. auto storage class
  2. register storage class
  3. static storage class
  4. extern storage class

Note:-  Each variable in C belongs to one storage class. If we don't specify the storage class of a variable in its declaration, the compiler will assume a storage class depending on the context in which the variable is used. 

Banner to LogicGuns.com

Hide Page Information