Why do we need to use `int main` and not `void main` in C++?(为什么我们需要在 C++ 中使用 `int main` 而不是 `void main`?)
问题描述
为什么我们需要在 C++ 中使用 int main
而不是 void main
?
简短的回答,是因为 C++ 标准要求 main()
返回 int
.>
您可能知道,main()
函数的返回值被运行时库用作进程的退出代码.Unix 和 Win32 都支持进程完成后从进程返回的(小)整数的概念.从 main()
返回一个值为程序员提供了一种指定该值的方法.
Why do we need to use int main
and not void main
in C++?
The short answer, is because the C++ standard requires main()
to return int
.
As you probably know, the return value from the main()
function is used by the runtime library as the exit code for the process. Both Unix and Win32 support the concept of a (small) integer returned from a process after it has finished. Returning a value from main()
provides one way for the programmer to specify this value.
这篇关于为什么我们需要在 C++ 中使用 `int main` 而不是 `void main`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么我们需要在 C++ 中使用 `int main` 而不是 `


基础教程推荐
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17