C storage class determines



Storage class of variable Determines following things –

  1. Where the variable is stored
  2. Scope of Variable
  3. Default initial value
  4. Lifetime of variable

A. Where the variable is stored :

Storage Class determines the location of variable , Where it is declared. Variables declared with auto storage classes are declared inside main memory whereas variables declared with keyword register are stored inside the CPU Register.

B. Scope of Variable

Scope of Variable tells compile about the visibility of Variable in the block. Variable may have Block Scope , Local Scope and External Scope. Wiki has defined variable scope as –
[box]In computer programming, a scope is the context within a computer program in which a variable name or other identifier is valid and can be used, or within which a declaration has effect[/box]

C. Default Initial Value of the Variable

Whenever we declare a Variable in C, garbage value is assigned to the variable. Garbage Value may be considered as initial value of the variable. C Programming have different storage classes which has different initial values such as Global Variable have Initial Value as 0 while the Local auto variable have default initial garbage value.
Garbage value inside that address remains the same.

D. Lifetime of variable

Lifetime of the = Time Of     -   Time of Variable
  variable        Declaration       Destruction

Suppose we have declared variable inside main function then variable will be destroyed only when the control comes out of the main .i.e end of the program.