+ 1
Can someone explain when we have to use RETURN in function and when we dont have to
2 Respostas
+ 2
If at the end of your function some object must be given back to the caller (for example, a function to sum its arguments will give back the result of the sum; a function to instantiate a class will give back a pointer to the instantiated object), then your function will need a "return" clause followed by the object (integer, pointer) to be returned.
If your function will return nothing ("void": for example a function to print to the console; an initializer for a generator of random numbers) you do not need any "return" clause at the end of the function. You may need it - without any object associated to it - only if you want to go out of the function under certain circumstances, and under other circumstances the function may continue.
+ 2
If it is void you do not need to return. Otherwise you do.