August 2012
Intermediate to advanced
976 pages
30h 17m
English
A return with no value may be used only in a function that has a return type of void. Functions that return void are not required to contain a return. In a void function, an implicit return takes place after the function’s last statement.
Typically, void functions use a return to exit the function at an intermediate point. This use of return is analogous to the use of a break statement (§ 5.5.1, p. 190) to exit a loop. For example, we can write a swap function that does no work if the values are identical:
void swap(int &v1, int &v2){ // if the values are already the same, no need to swap, just return ...
Read now
Unlock full access