break下:
#include <stdio.h> int main() { int x = 1, a = 0, b = 0; switch(x) { case 0: b++; break; case 1: a++; break; case 2: a++; b++; break; } printf("a = %d, b = %d\n", a, b); return 0; }
no break:
#include <stdio.h> int main() { int x = 1, a = 0, b = 0; switch(x) { case 0: b++; case 1: a++; case 2: a++; b++; } printf("a = %d, b = %d\n", a, b); return 0; }
试着对比下运行结果。