[[noreturn]] void exit (int status);
Terminate calling process
Terminates the process normally, performing the regular cleanup for terminating programs.
Normal program termination performs the following (in the same order):
- Objects associated with the current thread with thread storage duration are destroyed (C++11 only).
- Objects with static storage duration are destroyed (C++) and functions registered with atexit are called.
- All C streams (open with functions in <cstdio>) are closed (and flushed, if buffered), and all files created with tmpfile are removed.
- Control is returned to the host environment.
Note that objects with automatic storage are not destroyed by calling exit (C++).
If status is zero or EXIT_SUCCESS, a successful termination status is returned to the host environment.
If status is EXIT_FAILURE, an unsuccessful termination status is returned to the host environment.
Otherwise, the status returned depends on the system and library implementation.
For a similar function that does not perform the cleanup described above, see quick_exit.
- Status code.
If this is
0 or EXIT_SUCCESS, it indicates success.
If it is EXIT_FAILURE, it indicates failure.
none (the function never returns).
/* exit example */
#include <stdio.h> /* printf, fopen */
#include <stdlib.h> /* exit, EXIT_FAILURE */
int main ()
FILE * pFile;
pFile = fopen ("myfile.txt","r");
printf ("Error opening file");
/* file operations here */
Calling this function destroys all objects with static duration: A program with multiple threads running shall not call exit (see quick_exit for a similar function that does not affect static objects).
No-throw guarantee: this function never throws exceptions.
If the program termination process described above throws an exception, terminate is automatically called.
- Abort current process (function
- Set function to be executed on exit (function