C - Storage Classes


  • Till now we know that how to declare and initialize a variable , but reality is that it is not complete . To fully define a variable one needs to mention not only its 'datatype' but also its 'storage class'. Not only all variables do have datatype ,thay also have a 'storage class'.
  • We have not mention storage class yet, though we have written several programs in c . We were able to get away with this , because storage class have defaults.
  • if we dont specify the storage class of a variable in its declaration , the compiler will automatically assign some storage class to it based on context in which the variable is used.
  • From compilers point of view , a variables name identifies some physical location within computers. There are basically two types of locations where value of variable may be kept.
  • I) MEMORY
    II)REGISTERS

  • It is variables storage class which determines that where the value will be stored.
    variable storage class tells us about,

I) Where the variable would be stored.
II) what will be initial value of variable , if variable is not given any value while declaring i.e not initialized .
III)what is scope of variable ,i.e. in which function the value of variable would be available.
IV) What is life of variable i.e. in which function the value of variable would be available.

There are four types of Storage class :

1)Automatic storage classes
2)Register storage classes
3) Static storage classes
4)External storage class

AutomaticRegisterStatic External
StorageMemoryCpu registersmemorymemory
Default initial value Garbage value Garbage value Zero Zero
Scope Local to block in which variable is defined Local to block in which variable is definedLocal to block in which variable is defined Global
Life Till the control remains within the block in which they are defined Till the control remains within the block in which they are defined Till the control remains within the block in which they are definedTill the end of program

  • Print Page