Variables: Global, Local variable : Variable Scope « Function « C++






Variables: Global, Local variable

Variables: Global, Local variable
 



#include <iostream>
using namespace std;
int gVar1;            
int gVar2 = 2;        
int main()
{
   char ch('A');  
                  
   cout << "Value of gVar1:    " << gVar1  << endl;
   cout << "Value of gVar2:    " << gVar2  << endl;
   cout << "Character in ch:   " << ch     << endl;
   int sum, number = 3; // Local variables with
                        // and without initialization
   sum = number + 5;
   cout << "Value of sum:      " << sum  << endl;
   return 0;
} 

           
         
  








Related examples in the same category

1.Variable Scope ExampleVariable Scope Example
2.Function with global value
3.The Scope Resolution Operator
4.Effect of scope on automatic variables
5.global variables