注:斜塔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