Consider this:
What if I want to assign the value of global variable a to b?Code:#include <stdio.h> int a = 10; int main(void) { int a = 15; int b = a; return 0; }
Consider this:
What if I want to assign the value of global variable a to b?Code:#include <stdio.h> int a = 10; int main(void) { int a = 15; int b = a; return 0; }
Then don't do something stupid like having two variables of the same name.
Make a pointer to it first.
Quzah.
Hope is the first step on the road to disappointment.
In C++ you can reference it by saying:
But that's entirely irrelevent here...Code:int b = ::a;
If I recall correctly, the local variable will be used in this situation.Originally Posted by csisz3r
Thus making your global variable usage in main useless.
I know you were just curious. But avoid doing that.
Easy, I'll make the change below:Originally Posted by csisz3r
Code:#include <stdio.h> int a = 10; int main(void) { int a = 15; int b = a; b = 10; return 0; }
Originally Posted by cwr
lol. guys, guys...
that's one great big reason why global variables are considered taboo -- its too easy to hide them, thus using the wrong version.
I think this will do what you want.i just remembered what my teacher said "FOOLISH QUESTION GET FOOLISH ANSWER".Code:#include <stdio.h> int a = 10; int main(void) { { int a = 15;} int b = a; return 0; }
No offence
Hey, my foolish answer is better