switch 语句中必先执行default语句???
# include<stdio.h>main()
{
int c=0,k,
for(k=1;k<3;k++)
switch(k)
{ default:c+=k;
case 2:c++;break;
case 4:c+=2; break;
}
printf("%d\n",c);
}
执行结果???
在switch 语句中default 执行顺序???
2010-02-26 13:52
2010-02-26 14:10
当没有case匹配时,执行defalut
2010-02-26 15:09
程序代码:switch (n)
{
case 1:
printf("find 1");
break;
case 2 :
printf("find 2");
break;
default:
printf("not 1 not 2");
break;
}只有在n即不等于1,也不等于2时,才会输出not 1 not 2。否则,n为1,输出find 1。n为2,输出find 2。

2010-02-26 23:10
2010-02-27 14:18