例如:
#include <stdio.h>
int main() {
int x = 3;
int y = 3;
switch (x % 2) {
case 1:
switch (y)
{
case 0:
printf("first");
case 1:
printf("second");
break;
default: printf("hello");
}
case 2:
printf("third");
}
return 0;
}
上述打印结果为“hellothird”!这就是结束没写break的结果!它打印完hello后就默认内循环和外循环都结束了,但没跳出来,就会依次执行下面的语句,导致打印出third!
本文通过一个C语言switch语句的示例,展示了当省略break语句时程序的行为。具体而言,介绍了如何在一个嵌套的switch结构中实现不同条件下的输出,并解释了未使用break时代码如何继续执行下一个case。
1万+

被折叠的 条评论
为什么被折叠?



