The Scope Resolution Operator( :: )
Global variables are explained outside any functions and thus can be used by all the functions defined thereafter. However, if a global variable is declared with the similar name as that of a local variable of a function , the local variable is the one in the scope when the program implements that function . The C++ language provides the scope resolution operator ( :: ) to access the global variable thus overriding a local variable with the similar name. This operator is prefixed to the name of the global variable . The following example shows its usage.
int global = 10;
void main()
{
int global = 20;
printf(" Just writing global prints : %d\n", global);
printf(" Writing ::global prints : %d\n", ::global);
}
The output of this program will be:
Just writing global prints : 20
Writing ::global prints : 10