Returning Control from a Function to Its Caller

There are several ways to return control to the point at which a function was invoked. If the function does not return a result (i.e., it has a void return type), control returns when the program reaches the function-ending right brace, or by execution of the statement


If the function does return a result, the statement

         return expression;

evaluates expression and returns the value of expression to the caller. Some compilers issue errors and others issue warnings if you do not provide an appropriate return statement in a function that’s supposed to return a result.

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.