The standard C library provides a function named atexit() that can be used to perform ?cleanup? operations when your program terminates. You can set up a set of functions you want to perform automatically when your program exits by passing function pointers to the at exit() function.
This can be done by using #pragma directive as: #pragma exit <function name>
Using above code, any function can be executed after program exits the main function but function must be declared before pragma directive is reached.
To be more precise, atexit is used to register the exit functions which will be called upon upon exit from main(). I also remember that upto 42 functions can be registered using atexit(). I don't know what this "magical" number is chosen, though. e.g: atexit(Bye1); atexit(Bye2); .. atexit(Bye42);
where Bye1,Bye2,..Bye42 will be called in succession.