What is the need of return value in c or cpp? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the need of return value in c or cpp?

I can't understand the concept of the return value.

21st Aug 2019, 1:59 AM
Gouri Biswas Das
Gouri Biswas Das - avatar
1 Answer
+ 4
A function may be designed to return something to the caller (or not at all). The something could be a simple math calculation result to a complex object created and initialized in the function. It all depends on needs. The `return` statement is used to (duh) return that something to the caller (in case the function was designed to return some type); the use of `return` in a function that wasn't designed to return anything means that the execution point must leave the function prematurely, leave the rest of statements without executing them, and return to the last execution point - which most likely be somewhere in its caller block where the function was invoked..
21st Aug 2019, 2:26 AM
Ipang