Now that you've seen how to declare what your function is going to return,
how do you actually return a variable? It's actually pretty easy. Anywhere
in your function, just say " return yum;
At that point, the function stops and that variable is returned. Be
careful, this is unlike Pascal, where you could assign the value you would
return and the function would keep going. For example, if you had the function
say " int number_of_doritos(void) { int yum; yum = 523; /* That's a lot of doritos! */ return yum; /* Returns the value in yum, stops the function */ cout << "I hate doritos!" << endl; /* Nobody ever sees this */ } |