Table of Contents
Previous Section Next Section

return

The return statement forces a return from a function and can be used to transfer a value back to the calling routine. It has these two forms:

return;
return value;

In C99 and C++, the form of return that does not specify a value must be used only in void functions.

The following function returns the product of its two integer arguments:

int mul(int a, int b)
{
  return a*b;
}

Keep in mind that as soon as a return is encountered, the function will return, skipping any other code that may be in the function.

Also, a function can contain more than one return statement.


Table of Contents
Previous Section Next Section