What is Scope Resolution Operator in C++?
![]() Don't want to miss a single bit? Subscribe By Email for Daily Jobs |
There are two used of the scope resolution operator in C++.
The first use being that a scope resolution operator is used to unhide the global variable that might have got hidden by the local variables. Hence in order to access the hidden global variable one needs to prefix the variable name with the scope resolution operator (:Smile.
e.g.
int i = 10;
int main ()
{
int i = 20;
Cout << i; // this prints the value 20
Cout << ::i; // in order to use the global i one needs to prefix it with the scope
//resolution operator.
}
The second use of the operator is used to access the members declared in class scope. Whenever a scope resolution operator is used the name of the member that follows the operator is looked up in the scope of the class with the name that appears before the operator.
Related Articles
- What is Operator Overloading in C++ ?
- What are Friend Functions and Friend Classes in C++ ?
- What are Pointers in C++ (Object Oriented Programming) ?
- What are the Standard Exceptions in C++ ?
- What are the Storage Types for Variables in C++ ?


