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;
}
Printable View
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.
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.Quote:
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:Quote:
Originally Posted by csisz3r
Code:#include <stdio.h>
int a = 10;
int main(void)
{
int a = 15;
int b = a;
b = 10;
return 0;
}
Quote:
Originally Posted by cwr
lol. guys, guys...
pointers are your friend.
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". :DCode:#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 :D