What is a scope resolution operator?
Scope resolution operator is used to uncover the hidden variables. It also allows access to global version of variables.
Program Code:
#include<iostream>
using namespace std;
// global variable x of the program
int x=10;
int main( )
{
// local variable x of the program
int x=20;
cout<<"This is the value of local variable x = "<<x;
cout<<endl;
// to access global variable in main program use scope resolution operator (::) in front of global variable
cout<<"This the value of global variable x = "<<::x;
cout<<endl;
return 0;
}
The program output is tested on www.jdoodle.com
Output:
This is the value of local variable x = 20
This the value of global variable x = 10
Thanks
Mukesh Rajput
Post A Comment:
0 comments: