Can we access global variable if there is a local variable with same name?
In C, we cannot access a global variable if we have a local variable with same name, but it is possible in C++ using scope resolution operator (::).
x = 10;
"Value of global x is "
<< ::x << endl;
"Value of local x is "
Value of global x is 0
Value of local x is 10
Please write comments if you find anything incorrect in the above GFact or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.