注:斜塔C++背景与蟒蛇背景C++的条件语句
在最后如果看代码如下声明: 什么呢I = 1 if语句之后的意思。 看最后的其他语句。 在else语句之后,i = 0是什么意思? 为什么他们有
#include <stdio.h> // preprocessor command
int foo(int x) // function definition
{
return x+1; // return expression value
}
int main() // this is where all C programs start
{
int i = 0; // variable definition + init.
while (i < 10)
{ // loop + condition
i = i+1; // expression + assignment
printf("%d ", foo(i)); // function calls, output
}
if (i >= 10) i = 1; // conditional code execution
else i = 0;
return i; // return result, exit function
}
我不知道,如果你问_why_他们在那里或_how做陈述的工作?_但如果是前者,你正在做一个检查,看是否while循环完全执行,然后返回1,如果没有则返回0。返回码对错误检查等有用。 – JMercer