return;orreturn ;PS: not function, statement!
36.6
It means end the function. Functions automatically end when execution reaches the end of the function, but you can return from a function at any point within the function with a return statement. If the function returns a value to its caller, you must provide a reachable return statement along with the value you wish to return.
Classes cannot return values, only functions can return values. But you cannot return a function from a function, you can only return a function pointer -- a pointer variable holding the address of the function you wish to return. All possible return values must be of the same type, therefore all function signatures and return types must be exactly the same -- only the name of the functions can differ.
// Taking Damage // Demonstrates function inlining #include <iostream> int radiation(int health); using namespace std; int main() { int health = 80; cout << "Your health is " << health << "\n\n"; health = radiation(health); cout << "After radiation exposure your health is " << health << "\n\n"; health = radiation(health); cout << "After radiation exposure your health is " << health << "\n\n"; health = radiation(health); cout << "After radiation exposure your health is " << health << "\n\n"; return 0; } inline int radiation(int health) { return (health / 2); }
The set of all values that a function will return as outputs is called the *range* of the function.
If we consider any function that is not the main function that is declared as "bool" i.e it will return boolean values to the main function-0 & 1, meaning 'false' and 'true' respectively. If we have to tell the main function that the condition checked in the function is false or disagreed, then we return 0 to the main function and when we have to tell that the condition checked in the main function is true or agreed, then we return 1 to the main function.
Where there is no need to return any type of value from a function
return
return is not necessary if the return type is void, and you want to leave the function only at its end.
echo function();
The return statement is used in functions to return control to the caller. If the function is declared non-void, the return statement also allows the programmer to return a value to the caller.