Registers a function that is called without arguments at program termination. Format #include <stdlib.h> int atexit (void (*func) (void));
1 – Argument
func A pointer to the function to be registered.
2 – Return Values
0 Indicates that the registration has succeeded. nonzero Indicates failure.
3 – Restriction
The longjmp function cannot be executed from within the handler, because the destination address of the longjmp no longer exists.
4 – Example
#include <stdlib.h> #include <stdio.h> static void hw(void); main() { atexit(hw); } static void hw() { puts("Hello, world\n"); } Running this example produces the following output: Hello, world