C++ Doubt
-
#include int i = 7; //The above i can be accessed using the global namespace //:: Operator void main() { int i = 10; { int i = 15; { int i = 17; printf("%d\n",i); //How to Access The Remaining i's here in c and c++ } } } //The above variables have to be defined at the above point
-
#include int i = 7; //The above i can be accessed using the global namespace //:: Operator void main() { int i = 10; { int i = 15; { int i = 17; printf("%d\n",i); //How to Access The Remaining i's here in c and c++ } } } //The above variables have to be defined at the above point
you can't. the global i hides all of the other i's. use different names. -c
-
#include int i = 7; //The above i can be accessed using the global namespace //:: Operator void main() { int i = 10; { int i = 15; { int i = 17; printf("%d\n",i); //How to Access The Remaining i's here in c and c++ } } } //The above variables have to be defined at the above point
In C you can only access the local i within your block of code (equal to 17). In C++ you can access the local i AND the global i (equal to 7). To access the global i, you'd use the scope resolution operator ( :: ) like this: printf("%d\n", ::i); Regards, Alvaro