main()在C和C++中定义函数的正确(最有效)方法是什么- int main()或void main()- 为什么?如果int main()那么return 1或return 0?
这个问题有很多重复,包括:
main()函数的有效签名是什么?main()函数void main()和int main()?main()在C++中的签名main()? - 对于C++,确实有一个非常好的答案.main()C语言中的函数样式main()C中的方法类型int main()vs void main()在C中有关:
What is the proper signature of the main function in C++? What is the correct return type, and what does it mean to return a value from main? What are the allowed parameter types, and what are their meanings?
这是系统特定的吗?这些规则会随着时间而改变吗?如果我违反它们会发生什么?
嘿所以我本周刚开始学习基本的c ++,我有一个问题说:
编写一个程序来比较3个整数并打印最大的,程序应该只使用2个IF语句.
我不知道如何做到这一点所以任何帮助将不胜感激
到目前为止我有这个:
#include <iostream>
using namespace std;
void main()
{
int a, b, c;
cout << "Please enter three integers: ";
cin >> a >> b >> c;
if ( a > b && a > c)
cout << a;
else if ( b > c && b > a)
cout << b;
else if (c > a && c > b)
cout << b;
system("PAUSE");
}
Run Code Online (Sandbox Code Playgroud)