atexit
#include <stdlib.h> #include <stdio.h> void bye() { printf("byte\n"); } void goodbyte() { printf("good byte\n"); } int main(int argc, char *argv[]) { atexit(bye); //bye will be called after exit atexit(goodbyte); //goodbyte will be called after exit printf("hello\n"); return 0; }