为什么这个代码在visual studio 2017中工作,即使我使用的return语句的数字不等于零? [英] Why this code works in visual studio 2017 even when I used return statement with digit something different than zero?
问题描述
据说如果我们把'return 0'作为回报,这意味着代码是正常的,如果我们放任何其他整数意味着存在一些问题。
我尝试过:
it is said that in return if we put 'return 0' this means that code is alright and if we put any other integer that means there is some problem.
What I have tried:
#include <iostream>
int main()
{ std::cout<<"Hello World!";
return 4556;
}
推荐答案
据说如果我们把'return 0'作为回报,这意味着代码是正常的,如果我们放任何其他整数意味着存在一些问题。
it is said that in return if we put 'return 0' this means that code is alright and if we put any other integer that means there is some problem.
这是真的,但只是一个约定。在进程终止时,您必须明确请求操作系统获取返回代码,以便进行检查。请参阅如何做我从Windows命令行获取应用程序退出代码? - 堆栈溢出 [ ^ ]。在大多数情况下,特别是在Windows上,程序返回值明显被忽略。无论如何,遵循约定是一种很好的做法。
That is true, but is just a convention. On process termination, you have to explicitely request the OS for the return code, in order to check it. See, for instance How do I get the application exit code from a Windows command line? - Stack Overflow[^]. On most cases, expecially on Windows, the program return value is plainly ignored. It is good practice, anyway, to follow the convention.
为什么这段代码适用于视觉工作室2017甚至当我使用带有不同于零的数字的return语句时?
Why this code works in visual studio 2017 even when I used return statement with digit something different than zero?
返回值是你的程序告诉调用者是否有任何正确的结果。
当您在批处理命令文件中运行程序时,它是您的程序用来告诉批处理文件是否存在问题的意思。
这允许批处理文件根据具体情况做出决定返回值。
the return value is your program telling the caller if anything was correct or not.
When you run a program in a batch command file, it is the mean your program use to tell the batch file there was a problem or not.
This allow the batch file to make decision depending on that return value.
这篇关于为什么这个代码在visual studio 2017中工作,即使我使用的return语句的数字不等于零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!