首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

问个比较简单的有关问题

2013-03-29 
问个比较简单的问题#include stdio.hint main (void){int i 0while (i 3){switch (i++){case 0:pri

问个比较简单的问题

#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++值没变

热点排行