Use :: to reference global variable : global variable « Language Basics « C++ Tutorial






#include <iostream>
using namespace std; 
int global_name = 1001;

int main(void){
   int global_name = 1;  // Local variable

   cout << "Local variable value " << global_name << '\n';
   cout << "Global variable value " << ::global_name << '\n';
}








1.5.global variable
1.5.1.Use a global variable
1.5.2.Global class variable
1.5.3.Global variables are known throughout the entire program and may be used by any piece of code.
1.5.4.Use :: to reference global variable