C++ Programming Blog

 
 
 

Image

 #include<iostream.h>
 #include<conio.h>

 int increment_auto();
 int increment_static();

 int value_1=6;
 int value_2=9;

 main()
    {
       clrscr();

       int int_1;
       int int_2;

       cout<<\"\\n Auto storage class :\"<<endl;
       for(int count_1=1;count_1<=5;count_1++)
      {
         int_1=increment_auto();
         cout<<\" \"<<int_1;
      }

       cout<<\"\\n\\n Value of global variable value_1 = \"<<value_1<<endl;
       cout<<\" Value of global variable value_2 = \"<<value_2<<endl;


       cout<<\"\\n Static storage class :\"<<endl;
       for(int count_2=1;count_2<=5;count_2++)
      {
         int_2=increment_static();
         cout<<\" \"<<int_2;
      }

       value_1++;
       value_2++;

       cout<<\"\\n\\n Value of global variable value_1 = \"<<value_1<<endl;
       cout<<\" Value of global variable value_2 = \"<<value_2<<endl;

       getch();
       return 0;
    }


 //---------------------------  increment_auto( )  -----------------------//


 int increment_auto()
    {
       auto int value_1=5;

       value_1++;

       return value_1;
    }


 //-------------------------  increment_static( )  -----------------------//


 int increment_static()
    {
       static int value_2=5;

       value_2++;

       return value_2;
    }