Defining the Scope Resolution OperatorGlobal variables are defined outside any functions and thus can eb used by all the functions defined thereafter, However, if a global variable is declared with the same name as that of a local variable of a function. the local variable is the one in the scope when the program executes that funtction.The C++ language provides the scope resolution operator (::) to access the global variable thus overriding a local variable with same 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
Thanks !!
Nikhil