In C++ scope resolution operator is used to define a function outside a class. If a user has a local variable with same name as global variable and wants to use a global variable the we use the scope resolution operator.
int m=10; //(global m)
int m=20; //m declared local to main
int m=30;//m again local to inner block
cout<<"we are in innnerbloack\n";
cout<<"\n we are in outerbloack \n";
We are in inner block
We are in outer block
In the above program, variable m is declared mainly at following three places:
(i) Outside the main() function
(ii) Inside the main() function
(iii) Inside the inner block.
Note: ::m will always refer to the global m.In the inner block, ::m refer to value 10 and not 20.