Computer Science, asked by chitadhoomu0skajay, 1 year ago

why scope resolution operator is used

Answers

Answered by WrathRaiser
1
when you are writing code in a local scope(like in a method, constructor, lambda etc..) and you need to access a global variable which has the same variable name in the local scope you can use the scope resolution op to access the global var(can use for namespace as well)
example:
int x = 5;
void mymethod() {
int x = 6;
cout << x; // prints 6
cout << ::x; // prints 5
}
Answered by topper66
0
to access the global var(can use for namespace as well)
Similar questions