C Language

Function Return Statement

In C Language by Baqir AliLeave a Comment

A return statement causes the program logic to return to the point in the program from which the function was accessed.

The general form of a return statement is:

 return expression; 

This statement causes the value of expression to be returned to the calling part of the program. Of course, the data type of expression should match the declared data type of the function.

Some other examples:

 return 33;
 return a++;
 return (a+b)/c; 

You can enclose the expression being returned in parentheses, especially if the expression is complicated.

 return (expression); 

A maximum of one expression can be included in a return statement. Thus, a function can return a maximum of one value to the calling part of the program However, a function definition can include multiple return statements, each containing a different expression, which are conditionally executed, depending on the program logic.

Returning Nothing

A void type is used to indicate that a function does not return a value back to its calling function.

For a void function of the form:

  void f_name(...) 

which does not return any value, the appropriate return statement is simply: return;


Leave a Comment