+ 1
Scope of variable
Hi int x; void fun() { int x = 2; { int x = 3; cout << ::x << endl; } } Above code has int x as global variable. From fun function, ::X will print value of global variable and x will print value local to scope of {} which is 3. How can I print value of X as 2 from a local scope enclosed inside {} ?
1 Resposta
+ 2
I don't think it's possible. The variable x from main's scope is "shadowed" as they say.