Names specified here
Name Description Notes Source Availability
_Exit() Terminate program without registered activity (·) <stdlib.h> C99 C11
abort() Abort program execution (·) <stdlib.h> C89 C90 C95 C99 C11
at_quick_exit() Register activity on quick termination (·) <stdlib.h> C11
atexit() Register activity on normal termination (·) <stdlib.h> C89 C90 C95 C99 C11
EXIT_FAILURE Indication of program failure M <stdlib.h> C89 C90 C95 C99 C11
EXIT_SUCCESS Indication of program success M <stdlib.h> C89 C90 C95 C99 C11
exit() Terminate program (·) <stdlib.h> C89 C90 C95 C99 C11
main() Entry and exit point of program (·) User-defined C89 C90 C95 C99 C11
quick_exit() Terminate program without signals (·) <stdlib.h> C11
SIGABRT Execution aborted M <signal.h> C89 C90 C95 C99 C11

In a hosted environment, a C program begins with the invocation of a user-defined function called main, which must have one of the following prototypes:

int main(void);
int main(int argc, const char *const *argv);

A program may be executed with a list of textual arguments. argc indicates how many arguments were provided for the current execution, and these are passed as null-terminated strings argv[1], argv[2], etc. argv[argc] is always NULL. argv[0] is a pointer to a null-terminated string which is often the program name, or the name used to determine that this program should be executed.

A C program can end under several conditions, and may terminate normally or abnormally. When it terminates normally, all open streams are properly flushed and closed, and all temporary files are deleted.

When a program terminates, it does so with an exit status. The program terminates normally when the initial invocation of main terminates, and the return value of that invocation becomes the exit status. The exit status of a program invoked with system is returned by that function.

Programs should exit with status 0 or EXIT_SUCCESS to indicate that the program was successful, or with EXIT_FAILURE to indicate that it failed to do what was intended. Other values may be returned to signify other implementation-defined meanings. EXIT_SUCCESS and EXIT_FAILURE are defined in <stdlib.h>.

#include <stdlib.h>
_Noreturn void exit(int status);
_Noreturn void _Exit(int status);
_Noreturn void quick_exit(int status);

A program may exit prematurely, but normally, by calling exit, quick_exit or _Exit. The argument becomes the exit status.

#include <stdlib.h>
void atexit(void (*func)(void));
void at_quick_exit(void (*func)(void));

User-defined functions may be specified to be executed during program termination. Two lists of functions are defined, with atexit adding the function pointer func to one of them, and at_quick_exit adding to the other. Both functions add to the heads of their respective lists.

If a program terminates with exit, or by returning from main, the functions in the list established by atexit are executed. Terminating with quick_exit first invokes the functions in the list established by at_quick_exit. _Exit invokes no functions from either list.

#include <stdlib.h>
_Noreturn void abort(void);

abort causes abnormal termination of the program by invoking raise(SIGABRT). The exit status is unspecified, except that it will be distinct from 0 and EXIT_SUCCESS. assert calls abort when its assertion fails.


CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2023-10-04T20:24:03.201+0000