注册退出函数:atexit

原型:int atexit(void (*func)(void))

依赖库:stdlib.h

atexit 可注册一个退出函数,当函数结束时调用。如果函数成功注册,则该函数返回零,否则返回一个非零值

 

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 void print()
 4 {
 5     printf("It's clearing.\n");
 6 }
 7 int main()
 8 {
 9     atexit(print);
10     printf("程序开始\n");
11     printf("程序结束\n");
12 }

输出结果:

  程序开始 

  程序结束
  It's clearing.

 

posted @ 2021-10-21 14:59  孱陵  阅读(129)  评论(0编辑  收藏  举报