What is a return value?

What is the return value of a function? How is it different from the answer a code calculates? And what is avoid function?

Last edited on
the quick answer from math: y = f(x); y is the return value.

How is it different from the answer a code calculates?
^ Bad question is bad. There may be no difference, or all the difference in the world, depending on the code.

void functions do not return a value:
void printhey()
{
cout << "hey world and stuff"; //what to return here? there isnt anything
}
Last edited on
1
2
3
4
5
int money()
{
     int answer = 10+5;
     return answer; //Return an integer - The same return type as the function.
}


Return values are what you want the function to return. For example, after some math, you may want the function to give you the answer I'd assume! Which can be used like this:

 
int math = money(); //This will call money(), and the function will return 15 


^When it returns 15, math will = 15.

Void functions don't return anything, they simply do what you code then exit.
Topic archived. No new replies allowed.