Automatic storage class


Automatic Storage Class:

·       It stores variable in memory
·       Initial value of automatic class variables is garbage values.
·       Variable scope is local to block in which it is defined.
·       Life of variable will be only till control remains in block.
·       Keyword - auto

Example: 
                 This example shows how to define a auto variable.

    
     #include<stdio.h>

     main( )
     {
          auto int i, j ;
          printf ( "\n%d %d\n", i, j ) ;
}

In this example, we did not initialize I and j variable, so it displays garbage values after execution.



   Example 2 : this example will illustrate scope of auto variable.

#include<stdio.h>

main( )
{
          auto int test=100;
          {
                    auto int test=200;
                    {
                              auto int test=300;
                             printf("%d   ",test); 
                    }
                  printf("%d   ",test);   
          }
          printf("%d",test); 
}


Comments

Popular posts from this blog

Disable or enable proxy for Internet explorer or Chrome

chm viewer unable to show contents

3 prisoners and 5 hats puzzle