Storage class in c

The storage class determines the part of the memory where the variable would be stored,how long the variable would exist,the initial value of the variuable and the scope of the variable.

There are 4 storage class in c:

  • Automatic storage class
  • Register storage class
  • Static storage class
  • External storage class   

Automatic storage class

An ordinary variable automatically resides in computer memory.

  1. Keywors: auto
  2. Storage: Memory
  3. Default initial value: Garbage value.
  4. Scope: Local to the block in which it is declared.
  5. Life: As long as the program control remains within the block in which it is declared.

             ex: auto int i;

Register storage class

The register class specifier indicates compiler that the value of the variable should reside in the CPU register.A value stored in a CPU register can be accessedfaster than the one which is stored in the memory.

  1. Keyword: register
  2. Storage: CPU Registers.
  3. Default initialvalue: Garbage value.
  4. Scope: Local to the block in which it is declared.
  5. Life: As long as the program control remains within the block in which it is declared.

         ex: register int i;

Static storage class

  1. Keyword: static
  2. Storage: Memory
  3. Default initial value: Zero
  4. Scope: Local to the block in which it is declared.
  5. Life: Variable retains its value between different function calls.

          ex: static int i=0;

External storage class

  1. Keyword: extern
  2. Storage: Memory
  3. Default initial value: Zero
  4. Scope: In all functions of a program.
  5. Life: Throughout the program execution.

           ex: extern int i;

Posted on by