c - 奇怪的 for 循环条件

标签 c visual-studio for-loop

即使给定的条件只是 t,这个 for 循环仍然有效。

当它甚至不是一个有效的条件时,这怎么可能? 还有很多其他类似的异常(exception)吗?

for (t=10; t; --t) {
  printf("%d",t);
}    

最佳答案

How is this possible when its not even a valid condition. Are there many other exceptions like this ?

这是可能且有效的条件。
for循环中的第二个子表达式t用于检查t是否等于0。它相当于

for (t=10; t != 0 ; --t) {...}

关于c - 奇怪的 for 循环条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21631090/

相关文章:

c - 如何找出在哪个内核版本中更改了 Linux 内核代码的哪一部分

visual-studio - 在 Windows 上对嵌入式软件进行原型(prototype)设计和模拟

python - Python 中 for 循环和打印列表的顺序是什么?

javascript - 编写 Array.every() 函数

c - 从 c 字符串中删除 charAt

c++ - fprintf 的成本

c - 在 Ubuntu 上安装的 TeamCity 服务器上构建 Visual Studio 项目

visual-studio - 在 Visual Studio 2008 中在拆分窗口之间跳转的热键是什么

python - 当使用 f.read() 每个字母的迭代循环

c - sizeof(var) 在 C 语言中总是有效吗?