我在维基百科上找到了这段代码。
#include <stdio.h>
int main(void)
{
int c;
while (c = getchar(), c != EOF && c != 'x')
{
switch (c)
{
case '\n':
case '\r':
printf ("Newline\n");
break;
default:
printf ("%c",c);
}
}
return 0;
}
我很好奇用作while循环条件的表达式:
while (c = getchar(), c != EOF && c != 'x')
它的作用很明显,但我以前从未见过这种结构。这是特定于while循环的吗?如果不是,解析器/编译器如何确定逗号分隔表达式的哪一侧为while循环返回布尔值?