HP C/iX Reference Manual (31506-90011)

98 Chapter6
Statements
The return Statement
The return Statement
The return statement causes a return from a function.
Syntax
return
[expression]
;
Description
When a return statement is executed, the current function is terminated and control
passes back to the calling function. In addition, all memory previously allocated to
automatic variables is considered unused and may be allocated for other purposes.
If an expression follows the return keyword, the value of the expression is implicitly cast
to match the type of the function in which the return statement appears. If the type of the
function is void, no expression may follow the return statement.
A given function may have as many return statements as necessary. Each may (or may
not) have an expression, as required. Note that the C language does not require that
return statements have expressions even if the function type is not void. If a calling
program expects a value and a function does not return one (that is, a return statement
has no expression), the value returned is undefined.
Reaching the final } character of a function without encountering a return is equivalent to
executing a return statement with no expression.