What is returning the value | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is returning the value

3rd Feb 2017, 4:09 PM
praveenkumar
praveenkumar - avatar
2 Answers
+ 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.
3rd Feb 2017, 5:27 PM
Ladislav Milunović
Ladislav Milunović - avatar
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.
3rd Feb 2017, 4:35 PM
Al Dokhi Abdaullah
Al Dokhi Abdaullah - avatar