[try Beta version]
Not logged in

 
Really EASY problem to solve.....

Mar 16, 2011 at 12:21am
How do I declare a variable that CAN be changed but can be used in all functions of a program?

Like if I declare a variable in main, I can't use it in main2, get it?

I need a way to refer to and access a variable from all points of a program and change its value.

I'm not kidding, I really don't know how to do this and it's probably so simple....So please, some help. I need to know this for this program I'm almost finished with(the program moves from function to function and I need to be able to grab the contents and access/view them from all functions, but a constant variable used with #define is constant; won't change. I need a way to do this with a changeable variable)!
Last edited on Mar 16, 2011 at 12:24am
Mar 16, 2011 at 12:23am
1
2
3
4
5
int thisVariableCanBeAccessedGlobally = 0;
int main()
{
     cout << thisVariableCanBeAccessedGlobally;
}
Last edited on Mar 16, 2011 at 12:23am
Mar 16, 2011 at 12:24am
Huh?

I don't get it....Explain a bit of it, please?
Last edited on Mar 16, 2011 at 12:25am
Mar 16, 2011 at 12:30am
If you declare the variable outside of any function, and above any functions that use it, you can access it from all of those functions.

Mar 16, 2011 at 12:42am
Then what are static variables good for?

Also, why did you take so long to answer?
Last edited on Mar 16, 2011 at 12:42am
Mar 16, 2011 at 1:52am
No one is going to kick him? He has threads all around this site just completely trolling.
Mar 16, 2011 at 2:00am
Somehow, I think the fact that for newer users the "Report" feature has been changed to a "Report+Delete" feature has made some of us a bit more hesitant to use it...

-Albatross
Mar 16, 2011 at 2:01am
Yes, but the thing is while he obviously acts stupid, he does technically not violate any rules right now (that I am aware of). A bit annoying, yes, but better than his previous misdeeds.
Mar 16, 2011 at 2:05am
Well... there was one thread with an inappropriate title.

-Albatross
Mar 16, 2011 at 9:58am
closed account (z05DSL3A)
Yes, but the thing is while he obviously acts stupid, he does technically not violate any rules right now (that I am aware of). A bit annoying, yes, but better than his previous misdeeds.

I was trying to work out if he was a complete fool, trying not to get banned (the account has been suspended), or a Wind-up merchant that was trying to get passed the instant delete milestone. I was just waiting for the abusive rant.
Mar 16, 2011 at 7:22pm
I was going to give helpful input but when people on forums complain about how long it took for others to give an answer it bothers me. just sayin...
Topic archived. No new replies allowed.