HP C A.06.05 Reference Manual

Statements
return
Chapter 6174
return
Syntax
return; /* first form */
return
exp
; /* second form */
Arguments
exp
Any valid C expression.
Description
The return statement causes a C program to exit from the function containing the return
and go back to the calling block. It may or may not have an accompanying
exp
to evaluate. If
there is no
exp
, the function returns an unpredictable value.
A function may contain any number of return statements. The first one encountered in the
normal flow of control is executed, and causes program control to be returned to the calling
routine. If there is no return statement, program control returns to the calling routine when
the right brace of the function is reached. In this case, the value returned is undefined.
Return Types
The return value must be assignment-compatible with the type of the function. This means
that the compiler uses the same rules for allowable types on either side of an assignment
operator to determine allowable return types. For example, if f() is declared as a function
returning an int, it is legal to return any arithmetic type, since they can all be converted to
an int. It would be illegal, however, to return an aggregate type or a pointer, since these are
incompatible types.
The following example shows a function that returns a float, and some legal return values.
float f(void)
{
float f2;
int a;
char c;
f2 = a; /* OK, quietly converts a to float */
return a; /* OK, quietly converts a to float */