Effect of scope on automatic variables : Variable Scope « Function « C++






Effect of scope on automatic variables

  
#include <iostream>

using namespace std;

int main()
{                     
   int count1 = 10;
   int count3 = 50;
   
   cout << "Value of outer count1 = " << count1 << endl;
   {                  
      int count1 = 20;
      int count2 = 30;
      cout << "Value of inner count1 = " << count1 << endl;
      count1 += 3;
      count3 += count2;
   }

   cout << "Value of outer count1 = " << count1
        << "Value of outer count3 = " << count3;

   return 0;
}
  
    
  








Related examples in the same category

1.Variables: Global, Local variableVariables: Global, Local variable
2.Variable Scope ExampleVariable Scope Example
3.Function with global value
4.The Scope Resolution Operator
5.global variables