Name
return
Synopsis
The return
statement ends the execution of the
current function and returns control to the caller. The value of the
expression in the return statement is returned to the caller as the
return value of the function.
Syntax:
return expression
;
Example:
int max( int a, int b ) // The maximum of a and b { return (a>b ? a : b); }
Any number of return
statements can appear in a
function.
The value of the return
expression is converted to
the type of the function if necessary.
The expression in the return
statement can be
omitted. This only makes sense in functions of type
void
, however—in which case the entire
return
statement can also be omitted. Then the
function returns control to the caller at the end of the function
block.
Get C Pocket Reference 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.