What is Scope Resolution Operator in C++?

October 28, 2007 · Filed Under C++ Questions, Placement Questions 



Don't want to miss a single bit? Subscribe By Email for Daily Jobs

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

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


Get Latest JobsAdda.com Jobs, news & updates  via Email