攻读计算机科学专业......
我真的无法想出这个例子......
我明白将第一个参数留空会让它表现得像真......
但是我不明白在第二个参数中留下变量的是什么......
我最不了解的是printf语句如何"更新"变量条件......
#include<stdio.h>
int main()
{
int x=1, y=1;
for(; y; printf("%d %d\n", x, y))
{
y = x++ <= 5;
}
printf("\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
2 1
3 1
4 1
5 1
6 1
7 0
Run Code Online (Sandbox Code Playgroud)
编辑:
我现在理解for循环结构部分.....
感谢您的回答 - 非常有见地的感谢!
在for循环中考虑这个结构:
for (a; b; c)
{
d;
}
Run Code Online (Sandbox Code Playgroud)
这将是会发生的事情:
你最后发生的事情是,代码的"c"部分正在打印它的价值y而且恰好是0.然后评估该条件.因为y == 0,for循环会因为0相当于而中断false.
| 归档时间: |
|
| 查看次数: |
3763 次 |
| 最近记录: |