Storage Classes
auto - storage class Automatic variables may be specified upon declaration  to be of storage class  auto.  However, it is not required; by default, storage class within a block is auto. Automatic variables declared with initializes are initialized each time the block in which they are declared is entered.  Memory is allocated automatically upon entry to a block and freed automatically upon exit from the block  The scope of automatic variables is local to the block in which they are declared, including any blocks nested within that block.
void function(void);  main()  {  int i=0;  while(i<4)  {  printf(&quot;i = %d\n&quot;,i);  function(); i++;  }  }  void function(void)  {  int i = 4;  printf(&quot;Initial Value of i = %d\n&quot;,i);  i = 7;  printf(&quot; Final Value of i = %d\n&quot;,i);  }   i = 0  Initial Value of i = 4  Final Value of i = 7 i = 1  Initial Value of i = 4  Final Value of i = 7  i = 2  Initial Value of i = 4  Final Value of i = 7  i = 3  Initial Value of i = 4  Final value of i = 7
{  int Count;  auto int Month;  }  auto int Month is the same as int Count  because it is the default, it is almost never used
Register Variables Register variables are a special case of automatic  variables. Automatic variables are allocated storage in the memory of the computer; however, for most computers, accessing data in memory is considerably slower than processing in the CPU. These computers often have small amounts of storage within the CPU itself where data can be stored and accessed quickly. These storage cells are called  registers .
int main()  {  /* block scope with the register specifier */ register int i;  . . .  for (i=0; i<MAX_NUM; i++) { /* some statements */ }  . . .  return 0; }
Declaration vs Definition Declaration  is simply to describe information ``about'' the variable.  Latter action of the compiler, allocation of storage, is more properly called the definition  of the variable.
External Variables External variables may be declared outside  any function block in a source code file the same  way any other variable is declared; by specifying its type and name. No storage class specifier is used - the position of the declaration within the file indicates external storage class. Memory for such variables is allocated when the program begins execution, and remains allocated until the program terminates.
#include<stdio.h> int a=1; void next(void); void next1(void); main() { printf(&quot;Declalation vs Definition\n&quot;); a=2; printf(&quot;a=%d\n&quot;,a); next(); next1(); printf(&quot;a=%d\n&quot;,a); } int b=0;  /* definition of external b*/ void next(void) { char a; /* auto a is defined*/ a='a'; b=77; /* external b accessed */ } extern int a; void next1(void) { float b; /* auto b defined */ b=19.2; a=13; /* external a is accesed*/ }
Static Variables Static automatic variables continue to exist even after the block in which they are defined terminates. Thus, the value of a static variable in a function is retained between repeated function calls to the same function.
#include<stdio.h> #define MAX 20 void sumit(); main() { int count; printf(&quot;Enter 5 Numbers\n&quot;); for(count=0;count<5;count++) { sumit(); } printf(&quot;Program Completed&quot;); getch(); } void sumit() { static int sum=0; int num; printf(&quot;Enter a Number\n&quot;); scanf(&quot;%d&quot;,&num); sum=sum+num; printf(&quot;The Current Total is:%d\n&quot;,sum); }

Storage classes

  • 1.
  • 2.
    auto - storageclass Automatic variables may be specified upon declaration to be of storage class auto. However, it is not required; by default, storage class within a block is auto. Automatic variables declared with initializes are initialized each time the block in which they are declared is entered. Memory is allocated automatically upon entry to a block and freed automatically upon exit from the block The scope of automatic variables is local to the block in which they are declared, including any blocks nested within that block.
  • 3.
    void function(void); main() { int i=0; while(i<4) { printf(&quot;i = %d\n&quot;,i); function(); i++; } } void function(void) { int i = 4; printf(&quot;Initial Value of i = %d\n&quot;,i); i = 7; printf(&quot; Final Value of i = %d\n&quot;,i); } i = 0 Initial Value of i = 4 Final Value of i = 7 i = 1 Initial Value of i = 4 Final Value of i = 7 i = 2 Initial Value of i = 4 Final Value of i = 7 i = 3 Initial Value of i = 4 Final value of i = 7
  • 4.
    { intCount; auto int Month; } auto int Month is the same as int Count because it is the default, it is almost never used
  • 5.
    Register Variables Registervariables are a special case of automatic variables. Automatic variables are allocated storage in the memory of the computer; however, for most computers, accessing data in memory is considerably slower than processing in the CPU. These computers often have small amounts of storage within the CPU itself where data can be stored and accessed quickly. These storage cells are called registers .
  • 6.
    int main() { /* block scope with the register specifier */ register int i; . . . for (i=0; i<MAX_NUM; i++) { /* some statements */ } . . . return 0; }
  • 7.
    Declaration vs DefinitionDeclaration is simply to describe information ``about'' the variable. Latter action of the compiler, allocation of storage, is more properly called the definition of the variable.
  • 8.
    External Variables Externalvariables may be declared outside any function block in a source code file the same way any other variable is declared; by specifying its type and name. No storage class specifier is used - the position of the declaration within the file indicates external storage class. Memory for such variables is allocated when the program begins execution, and remains allocated until the program terminates.
  • 9.
    #include<stdio.h> int a=1;void next(void); void next1(void); main() { printf(&quot;Declalation vs Definition\n&quot;); a=2; printf(&quot;a=%d\n&quot;,a); next(); next1(); printf(&quot;a=%d\n&quot;,a); } int b=0; /* definition of external b*/ void next(void) { char a; /* auto a is defined*/ a='a'; b=77; /* external b accessed */ } extern int a; void next1(void) { float b; /* auto b defined */ b=19.2; a=13; /* external a is accesed*/ }
  • 10.
    Static Variables Staticautomatic variables continue to exist even after the block in which they are defined terminates. Thus, the value of a static variable in a function is retained between repeated function calls to the same function.
  • 11.
    #include<stdio.h> #define MAX20 void sumit(); main() { int count; printf(&quot;Enter 5 Numbers\n&quot;); for(count=0;count<5;count++) { sumit(); } printf(&quot;Program Completed&quot;); getch(); } void sumit() { static int sum=0; int num; printf(&quot;Enter a Number\n&quot;); scanf(&quot;%d&quot;,&num); sum=sum+num; printf(&quot;The Current Total is:%d\n&quot;,sum); }