What#39;s the meaning of the return value of int main(), and how to display it?(int main()的返回值是什么意思,如何显示?)
问题描述
可能重复:
main() 在 C/C++ 中应该返回什么?
我有这个简单的 C 程序:
I have this simple program in C:
#include <stdio.h>
int main()
{
return 8;
}
返回值是什么意思,如何显示,或者如何使用?
What's the meaning of the return value, and how to display it, or how to use it?
推荐答案
返回值是什么意思?
用于将main()
函数的状态返回给main()
的调用者:
It is used to return the status of the main()
function to the caller of main()
:
参考:
C++03 标准:18.3 开始和终止
最后,控制权返回到宿主环境.如果状态为零或 EXIT_SUCCESS,则返回成功终止状态的实现定义形式.如果状态是EXIT_FAILURE,返回状态不成功终止的实现定义形式.否则返回的状态是实现定义的.
Finally, control is returned to the host environment. If status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned. Otherwise the status returned is implementation-defined.
如何展示,或者如何使用?
就像显示或使用任何其他函数的返回值一样.main()
只是 C/C++ 中的另一个函数,在这方面 main 没有什么特别之处.
Just as you would display or use return value of any other function. main()
is just another function in C/C++ there's nothing special about main in that regards.
这篇关于int main()的返回值是什么意思,如何显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:int main()的返回值是什么意思,如何显示?


- STL 中有 dereference_iterator 吗? 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 静态初始化顺序失败 2022-01-01
- 近似搜索的工作原理 2021-01-01
- C++ 协变模板 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01