代码改变世界

在main函数执行完后,再执行其他方法

2022-11-13 11:24  钟铧若岩  阅读(41)  评论(0编辑  收藏  举报

 

方法如下:

 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