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.

CategoryControl flow
KindKeyword / Statement
C standardC89 / 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 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏