问个比较简单的问题
#include <stdio.h>这段代码的输出结果是
int main (void)
{
int i = 0;
while (i < 3)
{
switch (i++)
{
case 0:printf ("fat ");
case 1:printf ("hat ");
case 2:printf ("cat ");
default:printf ("Oh no! ");
}
putchar ('\n');
}
return 0;
}
fat hat cat Oh no!
hat cat Oh no!
cat Oh no!
我认为第一行的输出结果应该是从hat开始,switch (i++) 里面i的值应该变成1了 为什么还执行了case 0后面的语句
c
[解决办法]
switch判断的是i++,不是i。i++值没变