为什么我们需要在 C++ 中使用 `int main` 而不是 `void main`?

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++ 中使用 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`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
STL BigInt class implementation(STL BigInt 类实现)
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)