Name

return statement — Returns from a function

Synopsis

               statement := return [expression] ;

The return statement returns control from a function to its caller. If the function returns void, the expression is typically omitted, or else expression must be of type void. If the function returns a non-void type, the expression must be convertible to the return type.

A function that returns non-void must have a return statement (except for main, which has an implicit return 0; if control reaches the end of the function).

See Also

expression, statement, Chapter 5

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.