The atexit() is a function that allows the user to register a function that has to be called based on program termination.
It is a predefined function that is included in stdlib header files.
Example 1
#include<stdio.h> #include<stdlib.h> void welcome(void){ printf("Welcome to New,"); } void world(void){ printf("World\n"); } int main(){ //test atexit ,call user defined function atexit(world); atexit(welcome); return 0; }
Output
Welcome to New,World
Example 2
#include<stdio.h> #include<stdlib.h> void first(void){ printf("This is a beautiful,"); } void second(void){ printf("Wonderful life\n"); } int main(){ //test atexit ,call user defined function atexit(second); atexit(first); return 0; }
Output
This is a beautiful,Wonderful life