Atexit() - C library function Program
Declaration :
1 |
int atexit(void (*func)(void)) |
Explanation :
Purpose | The C library function int atexit(void (*func)(void)) causes the specified function func to be called when the program terminates. You can register your termination function anywhere you like but it will be called at the time of program termination. |
Parameters | func ===> This is the function to be called at the termination of the program. |
Return Value | This function returns a zero value if the function is registered successfully otherwise a non-zero value if it is failed. |
Exception |
C Program : Example
The following example shows the usage of atexit() function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <stdio.h> #include <stdlib.h> void functionA () { printf("This is functionAn"); } int main () { /* register the termination function */ atexit(functionA ); printf("Starting main program...n"); printf("Exiting main program...n"); return(0); } |