The scope resolution operator is used to resolve or extend the scope of variable.
C++ is block structured language. We know that the same variable name can be used to have different meaning in different block.
The scope resolution operator is denotes as (::). It will refer value of global variable from anywhere. Without scope resolution operator all variable will refer local value.
Example:
#include<iostream.h>
int m=10;
int main()
{
int m=20;
{
int k=m;
int m=30;
cout<<"we are in inner block \n";
}
cout<<"k="<<k<<"\n";
cout<<"m="<<m<<"\n";
cout<<"::m="<<::m<<"\n";
return 0;
}
Output:
we are in inner block
k=20
m=30
we are in outer block
::m=10