atexit
int atexit ( void (* function) (void) ); | stdlib.h |
cplusplus.com |
Specifies a function to be executed at exit.
The function pointed by function parameter is called when the
program terminates normally.
If more than one atexit function is specified calling this, they are
all executed in reverse order, that is, the last function
specified is the first to be executed at exit.
ANSI standard specifies that up to 32 functions can be prefixed for a
single process.
These functions will not receive any parameter when called.
Parameters.
Return Value.
0 is returned if successful, or a non-zero value if an error occurs.
Portability.
Defined in ANSI-C.
Example.
/* atexit example */
#include <stdio.h>
#include <stdlib.h>
void fnExit1 (void)
{
printf ("Exit function 1.\n");
}
void fnExit2 (void)
{
printf ("Exit function 2.\n");
}
main ()
{
atexit (fnExit1);
atexit (fnExit2);
printf ("Main function.\n");
return 0;
}
Output:
Main function.
Exit function 2.
Exit function 1.