|
-
April 7th, 2006, 09:00 PM
#1
Passing data between functions and main
If I have declared variables in another function such as main, how do I access them in another function? (Instructor does not allow global variables)
-
April 8th, 2006, 12:47 AM
#2
Re: Passing data between functions and main
100 bottles of beer on the wall, 100 bottles of beer, take one down pass it around, 99 bottles of beer on the wall....
Code:
void f(int& x) {
// ...
}
int main() {
int x = 0;
f(x);
}
though here I'm taking your "access them in another function" rather literally by passing by reference.
-
April 8th, 2006, 11:00 AM
#3
Re: Passing data between functions and main
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|