exit() Terminate the program normally

exit() Terminate the program normally

exit() terminates normally without returning, flushing and closing streams. Use EXIT_SUCCESS or EXIT_FAILURE; unlike return, it exits the whole program.

Categorystdlib.h utilities
KindLibrary function
Header<stdlib.h>
C standardC89 / C90

📝 Syntax

void exit(int status);

⚙️ Parameters

status RequiredA termination status for the host environment: 0 or EXIT_SUCCESS denotes success, and EXIT_FAILURE denotes failure.

Returns: No value is returned because the function does not return.

▶ Example

Edit the C code below and click Run; the server compiles and executes it:

Output:

Before exit
⚠️ Warning exit() does not return to the call site, so subsequent statements are not executed. Do not call it when the current function must continue.
💡 Tip Normal termination calls functions registered with atexit() and flushes and closes open streams. Automatic local objects have no additional destructor mechanism in C.

📚 Related Tutorials

❓ FAQ

QWhat is the difference between exit and returning from main?
AReturning status from main is essentially equivalent to exit(status). However, exit can terminate the whole program from another function, whereas an ordinary return exits only the current function.
QDoes exit flush buffered printf output?
AYes. Normal termination through exit flushes and closes all open output streams, unlike abnormal termination or an abrupt process kill.
QIn what order does exit call functions registered with atexit?
AThey are called in reverse registration order, so the last function registered runs first. Normal termination also flushes and closes open streams; programs that require precise resource release should not rely solely on global exit cleanup.
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%

🙏 帮我们做得更好

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

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