我放 return 0 和不放程序有什么区别
What is the different between I put return 0 or don't put on the program
#include <stdio.h>
int main()
{
for (int i = 0; i < 10; i++)
{
printf("%d",i);
}
}
我只是想知道为什么程序的结果无论是否将return 0;
放在代码上结果仍然正确。
没有区别。
根据 C 标准,您可以在 main()
函数中省略 return 0;
(并且 仅在该函数 中省略),它仍然会表现为如果末尾有return 0;
.
C标准中的确切写法:
[…]reaching the } that terminates the main function returns a value of 0.
来自 n2346 §5.1.2.2.3 程序终止。
#include <stdio.h>
int main()
{
for (int i = 0; i < 10; i++)
{
printf("%d",i);
}
}
我只是想知道为什么程序的结果无论是否将return 0;
放在代码上结果仍然正确。
没有区别。
根据 C 标准,您可以在 main()
函数中省略 return 0;
(并且 仅在该函数 中省略),它仍然会表现为如果末尾有return 0;
.
C标准中的确切写法:
[…]reaching the } that terminates the main function returns a value of 0.
来自 n2346 §5.1.2.2.3 程序终止。