From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/program%2Fexit.html | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 devdocs/c/program%2Fexit.html (limited to 'devdocs/c/program%2Fexit.html') diff --git a/devdocs/c/program%2Fexit.html b/devdocs/c/program%2Fexit.html new file mode 100644 index 00000000..a7ae5e4f --- /dev/null +++ b/devdocs/c/program%2Fexit.html @@ -0,0 +1,51 @@ +

exit

Defined in header <stdlib.h>
void exit( int exit_code );
(until C11)
_Noreturn void exit( int exit_code );
+
(since C11)
(until C23)
[[noreturn]] void exit( int exit_code );
+
(since C23)

Causes normal program termination to occur.

+

Several cleanup steps are performed:

+

Notes

The functions registered with at_quick_exit are not called.

+

The behavior is undefined if a program calls exit more than once, or if it calls exit and quick_exit

+

The behavior is undefined if during a call to a function registered with atexit, the function exits with longjmp.

+

Returning from the the main function, either by a return statement or by reaching the end of the function, executes exit(), passing the argument of the return statement (or ​0​ if implicit return was used) as exit_code.

+

Parameters

+ +
exit_code - exit status of the program

Return value

(none)

+

Example

#include <stdio.h>
+#include <stdlib.h>
+ 
+int main(void)
+{
+    FILE *fp = fopen("data.txt","r");
+    if (fp == NULL)
+    {
+       fprintf(stderr, "error opening file data.txt in function main()\n");
+       exit( EXIT_FAILURE );
+    }
+    fclose(fp);
+    printf("Normal Return\n");
+    return EXIT_SUCCESS ;
+}

Possible output:

+
error opening file data.txt in function main()

References

See also

+ + + +
causes abnormal program termination (without cleaning up)
(function)
registers a function to be called on exit() invocation
(function)
+
(C11)
causes normal program termination without completely cleaning up
(function)
C++ documentation for exit
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/program/exit +

+
-- cgit v1.2.3