方法如下:
1 #include <stdio.h> 2 3 int atexit(void(*function)(void)); 4 void fn1(void), fn2(void); 5 6 int main(int argc, char **argv) { 7 printf("Hello, World!\n"); 8 atexit(fn1); 9 atexit(fn2); 10 return 0; 11 12 } 13 14 void fn1() 15 { 16 printf("come this\n"); 17 } 18 void fn2() 19 { 20 printf("come this 2\n"); 21 }
执行结果:
Hello, World!
come this 2
come this