The Scope Resolution Operator : Variable Scope « Function « C++






The Scope Resolution Operator

  
#include <iostream>

using namespace std;

int count1 = 100;                            

int main()
{                                            
   int count1 = 10;
   int count3 = 50;
   cout << "Value of outer count1 = " << count1 << endl;
   cout << "Value of global count1 = " << ::count1 << endl;

   {                                          
      int count1 = 20;                        
      int count2 = 30;
      cout << "Value of inner count1 = " << count1 << endl;
      cout << "Value of global count1 = " << ::count1 << endl;

      count1 += 3;
      count3 += count2;
   }

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

   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.Effect of scope on automatic variables
5.global variables