吃精什么体验:请大家帮忙 问一个exit的问题

来源:百度文库 编辑:高校问答 时间:2024/04/27 13:39:04
exit的效果问题
有人说:exit函数存在于头文件stdlib.h不过由于期使用率较高,不须包含头文件即可使用。
exit(1)退出程序回到C语言编辑状态。
exit(0)退出程序回到操作系统状态。
但我在C语言编辑环境下Turbo c下
分别输入两种代码。但看不出有什么不同。
main()
{
exit(0) /*(or exit(1))*/
}
请高手指教
谢谢两位朋友的解释,但我还想问问,既然exit(0) or exit(1)分别提供给系统,那系统知道这个程序是否正常执行,那我们如何知道是否正常执行。系统怎么提醒我们。当某个函数调用时,exit(0 or 1)都是退出,我们如何知道是正常退出还是非正常退出 05.11.24

The exit function, declared in the standard include file STDLIB.H, terminates a C++ program.

The value supplied as an argument to exit is returned to the operating system as the programs return code or exit code. By convention, a return code of zero means that the program completed successfully.

Note You can use the constants EXIT_FAILURE and EXIT_SUCCESS, defined in STDLIB.H, to indicate success or failure of your program.

Issuing a return statement from the main function is equivalent to calling the exit function with the return value as its argument.

main()的特点是在它的结束处有一个隐式的return(0)
而大多数的操作系统都会把该返回直解释为"程序成功完成了"

错了错了,如果exit(1)还是返回1给系统的,系统就认为这个程序没有执行成功

不管返回1 还是0,你运行看当然看不出来效果了

对于程序自身而言,没什么分别
有时候需要再一个程序里面调用另一个程序去完成一些功能,这个时候被调用程序退出是否正常就可以用来判断功能是否完成。