#include <stdio.h>
volatile int i;
int main()
{
int c;
for (i = 0; i < 3; i++)
{
c = i &&& i;
printf("%d\n", c);
}
return 0;
}
使用gcc
编译上述程序的结果是:
0
1
1
使用-Wall
或-Waddress
选项,gcc
会发出警告:
warning: the address of ‘i’ will always evaluate as ‘true’ [-Waddress]
在上面的程序中,c
被如何评估?
i && (&i)
?有趣的是我在SO上没有找到相同的帖子。 - irrelephantwhile (i &&& i <-- j) {}
可以翻译为“当i不为0且i减小到等于j时执行循环体”。注意,&&& 是一个自定义的逻辑运算符,表示逻辑与运算中的短路效应。 - kennytm