0
What is returning the value
2 Respostas
+ 1
So, when you define some function it can return a value or void. Void functions are usually used to set some value or print something out in the console. Returning a value means that function (for example int) evaluates some expression and returns its result so you can make use of it.
So when you define a function:
int square(int number){
return number*number
}
You can do something like this:
int a = 3;
int b = square(a);
You can assign the value which function returned to some variable, in this case, the value of b is 9 and you can do some other operations with it. You almost can say that function is a value that is returned by it.
0
after doing some work in a function/method, you need to pullout the result, so return is the way to pullout the result from that function/method.