exit和return
来源:互联网 发布:电脑硬盘保护软件 编辑:程序博客网 时间:2024/05/16 07:16
参考这里:http://stackoverflow.com/questions/461449/return-statement-vs-exit-in-main
Actually, there is a difference, but it's subtle. It has more implications for C++, but the differences are important.
When I call return
in main()
, destructors will be called for my locally scoped objects. If I callexit()
, no destructor will be called for my locally scoped objects! Re-read that. exit()
does not return. That means that once I call it, there are "no backsies." Any objects that you've created in that function will not be destroyed. Often this has no implications, but sometimes it does, like closing files (surely you want all your data flushed to disk?).
Note that static
objects will be cleaned up even if you call exit()
. Finally note, that if you useabort()
, no objects will be destroyed. That is, no global objects, no static objects and no local objects will have their destructors called.
Proceed with caution when favoring exit over return.
- return 和exit
- exit和return区别
- exit和return
- exit和return
- exit()和return
- 关于exit() 和 return ()
- exit和return区别
- return 和 exit
- exit 和 return
- return和exit
- return和exit
- return和exit()
- exit和return
- Exit()和return
- exit()和_exit()和return
- Exit() 和 Return() 的区别
- exit函数和return函数
- exit()和return小析
- 好好利用免费资源
- 倒三角2
- servlet 线程安全问题
- 黑马程序员——表连接,子查询
- 梭形
- exit和return
- 看字母
- CSDN资料设置里为什么上传图像的功能总是不给力呢?
- 求1/2-2/3+3/4-…+19/20的和
- ORALCE——utl_file包进行I/O操作
- 1/3-3/5+5/7-7/9…+19/21)的和
- xml 和 json是无法进行无损转换的
- libjd-eclipse.so
- 第十周实验报告 函数01