Click to See Complete Forum and Search --> : Passing data between functions and main


Behnood
April 7th, 2006, 09:00 PM
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)

laserlight
April 8th, 2006, 12:47 AM
100 bottles of beer on the wall, 100 bottles of beer, take one down pass it around, 99 bottles of beer on the wall....
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.

exterminator
April 8th, 2006, 11:00 AM
What are different methods to pass parameters to functions? (http://www.codeguru.com/forum/showthread.php?t=343473)