又该C和C ++的main()的回报? [英] What should main() return in C and C++?
问题描述
什么是正确的(最有效)的方式来定义在C和C ++中的的main()
功能 - INT的main()
或无效的主要()
- 为什么?
如果 INT的main()
然后收益1
或返回0
?
What is the correct (most efficient) way to define the main()
function in C and C++ — int main()
or void main()
— and why?
If int main()
then return 1
or return 0
?
的有此问题的众多副本,其中包括:的
- What是对C的
的main()
函数? 的有效签名 - 的返回类型
的main()
功能 - Difference之间的
无效的主要()
和INT的main()
? -
的main()
的签名在C ++中 - 什么是
的正确声明的main()
- ?对于C ++,有的确是一个很好的答案 - 返回
的主要类型()
在C法 -
INT的main()
VS无效的主要()
用C
的main()
样式>在C函数 - What are the valid signatures for C's
main()
function? - The return type of
main()
function - Difference between
void main()
andint main()
? main()
's signature in C++- What is the proper declaration of
main()
? — For C++, with a very good answer indeed. - Styles of
main()
functions in C - Return type of
main()
method in C int main()
vsvoid main()
in C
相关阅读:
- C ++ -
INT主(INT ARGC,字符** ARGV)
- C ++ -
INT主(INT ARGC,CHAR *的argv [])
- Is
的char * envp []
作为第三个参数的main()
便携式? - Must在
INT的main()
函数所有的编译器返回一个值? - Why在C和C
的main()
函数的类型++留给用户来定义? - 为什么
INT的main(){}
编译? -
的法律定义的main()
在C + + 14?
- C++ —
int main(int argc, char **argv)
- C++ —
int main(int argc, char *argv[])
- Is
char *envp[]
as a third argument tomain()
portable? - Must the
int main()
function return a value in all compilers? - Why is the type of the
main()
function in C and C++ left to the user to define? - Why does
int main(){}
compile? - Legal definitions of
main()
in C++14?
推荐答案
的返回值主
应说明程序是如何退出。正常退出一般是由重由一个返回值为0 psented $ P $主
。异常终止通常由非回零信号,但有非零codeS如何间preTED没有标准。另外,作为其他人所指出的,无效的主要()
是明确的C ++标准禁止的,不得使用。有效的C ++ 主
签名是:
The return value for main
should indicate how the program exited. Normal exit is generally represented by a 0 return value from main
. Abnormal termination is usually signalled by a non-zero return but there is no standard for how non-zero codes are interpreted. Also as noted by others, void main()
is explicitly prohibited by the C++ standard and shouldn't be used. The valid C++ main
signatures are:
int main()
和
int main(int argc, char* argv[])
这相当于
int main(int argc, char** argv)
另外值得一提的是,在C ++中, INT的main()
可以留给没有返回值此时它默认返回0。这也是如此用C99程序。无论是返回0应该被省略或未是公开辩论。有效的C程序主签名的范围要大得多。
It's also worth noting that in C++, int main()
can be left without a return value at which point it defaults to returning 0. This is also true with a C99 program. Whether return 0 should be omitted or not is open to debate. The range of valid C program main signatures is much greater.
此外,效率是不符合主
功能的问题。它只能进入和离开一次(标记节目开始和终止)如C ++标准。对于C的情况不同,重新进入的main()
是允许的,但也许应该避免。
Also, efficiency is not an issue with the main
function. It can only be entered and left once (marking program start and termination) according to the C++ standard. For C, the case is different and re-entering main()
is allowed, but should probably be avoided.
这篇关于又该C和C ++的main()的回报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!