

Compile using: cl /W4 C_return_statement.c It demonstrates the return statement, and how it's used both to end function execution, and optionally, to return a value. This example is one program in several parts. If no return expression is supplied, the Microsoft C runtime returns a value that indicates success (0) or failure (a non-zero value). Microsoft-specific: The Microsoft C implementation returns the expression value to the process that invoked the program, such as cmd.exe. What happens to the returned value, if one is specified, depends on the implementation.

In a main function, the return statement and expression are optional.
CODEVISION RETURN CODE
The compiler may issue a warning diagnostic message about unreachable code if it finds any statements placed after the return statement. However, C doesn't require the parentheses.

Many programmers use parentheses to enclose the expression argument of the return statement. If a return type isn't specified, the C compiler assumes a default return type of int. If a return value isn't required, declare the function to have void return type. Use a plain return statement to make your intent clear.Īs a good engineering practice, always specify a return type for your functions. If the function has a void return type, this behavior is okay, but may be considered poor style. If the function has a return type other than void, it's a serious bug, and the compiler prints a warning diagnostic message. In this case, the return value of the called function is undefined. If no return statement appears in a function definition, control automatically returns to the calling function after the last statement of the called function is executed. When a return statement contains an expression in functions that have a void return type, the compiler generates a warning, and the expression isn't evaluated. The expression, if present, is evaluated and then converted to the type returned by the function. If expression is omitted, the return value of the function is undefined. The value of expression, if present, is returned to the calling function. A return statement can return a value to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement ends the execution of a function, and returns control to the calling function.
