The scope resolution operator (::) is used to bind a particular namespace to an identifier. It is mainly used to access the global variables and functions outside a class or a function. To write a program using scope resolution operator, you can use the following code:
#include <iostream.h>
#include<conio.h>
int globalVar = 10; // global variable
int main()
{
int localVar = 20; // local variable
clrcsr();
// Accessing global variable using scope resolution operator
cout << "Global Variable: " << ::globalVar << endl;
// Accessing local variable directly
cout << "Local Variable: " << localVar << endl;
getch();
return 0;
}
Tags
C plus plus