switch语句必须要加上break,否则会出现下面现象

例如:

#include 
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语言,蓝桥杯,gnu)