return Return from a function with an optional result
return Return from a function with an optional result
return ends the function and gives control to its caller. Results convert to the declared return type; void functions use return without an expression.
| Category | Control flow |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / C90 |
📝 Syntax
return expr; /* Or use return; in a void function */
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
sum = 5
🏷️ Related control-flow keywords
📚 Related Tutorials
❓ FAQ
QCan a void function use return 0?
AStandard C does not allow return with an expression in a void function. Use return; or simply reach the end of the function. Compiler extensions must not be treated as portable syntax.
QWhat does return 0 mean in main?
AReturning 0 from the initial call to main reports successful termination to the host environment, equivalent to calling exit(0) and performing the associated termination processing. A return from a recursive main call returns only to its caller; ordinary function returns likewise transfer control to their callers.
QDoes code after return still execute?
AStatements after return on the same execution path do not run because control has returned to the caller. Code in another conditional branch may still run if that execution path does not pass through the return.