HPlogo HP C/HP-UX Reference Manual: Workstations and Servers > Chapter 6 Statements

The return Statement

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

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 statement, 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 have an expression or not, 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.