main主函数执行完毕后,是否可能会再执行一段代码

来源:互联网 发布:越狱软件闪退 编辑:程序博客网 时间:2024/05/29 03:19

可以使用atexit()函数注册一个函数 1.#include 2. 3.//功能:Processes the specified function at exit. 4.//格式:int atexit( void ( __cdecl *func )( void ) ); 5.//描述:The atexit function is passed the address of a function (func) to be 6.// called when the program terminates normally. Successive calls to atexit 7.//create a register of functions that are executed in LIFO (last-in-first-out) 8.//order. The functions passed to atexit cannot take parameters. atexit and 9.//_onexit use the heap to hold the register of functions. Thus, the number of 10.// functions that can be registered is limited only by heap memory. 11.int atexit (void (*function)(void)); 12. 13. 14.#include 15. 16.void fun1(void); 17. 18.void fun2(void); 19. 20.void fun3(void); 21. 22.void fun4(void); 23. 24.void main() 25. 26.{ 27. 28. atexit(fun1); 29. 30. atexit(fun2); 31. 32. atexit(fun3); 33. 34. atexit(fun4); 35. 36. printf("this is executed first./n"); 37. 38.} 39. 40.void fun1() 41.{ 42. printf("next./n"); 43.} 44. 45.void fun2() 46.{ 47. printf("executed "); 48.} 49. 50.void fun3() 51.{ 52. printf("is "); 53.} 54. 55.void fun4() 56.{ 57. printf("this "); 58.}

原创粉丝点击