atexit
函数名: atexit 功 能: 注册终止函数(即main执行结束后调用的函数) 用 法: int atexit(atexit_t func); 注意:atexit()注册的函数类型应为不接受任何参数的void函数,exit调用这些注册函数的顺序与它们 登记时候的顺序相反。 程序例: #include <stdio.h> #include <
stdlib.h> void exit_fn1(void) { printf("Exit function #1 called/n"); } void exit_fn2(void) { printf("Exit function #2 called/n"); } int main(void) { /* post exit function #1 */ atexit(exit_fn1); /* post exit function #2 */ atexit(exit_fn2); return 0; } 输出: Exit function #2 called Exit function #1 called