Monthly Archives: July 2015
Dear readers, A friend of mine taught me this new “trick” where you can call a function when the main() in C exits.
In the Library “stdlib.h” there exists a function
int atexit(void (*func)(void))
the “func” is any function without any arguments.
The atexit() calls the function that you register as soon as the main() terminates.
Here is a simple sample code to demonstrate this.
printf(“This is after main\n”);
The function can be registered anywhere in the main() but it will be called only after the main() terminates.
Hope this helps atleast some of you in doing some cool things. Please feel free to share your ideas.