#include<stdio.h>
int a = 0, b = 2;
switch (++a,a*b)
{
case 1: printf("1");
case 2: printf("2");
case 3: printf("3\n");
default: printf("other\n");
}
return 0;
}
#include<stdio.h>
int a = 0, b = 2;
switch (++a,a*b)
{
case 1: printf("1");
case 2: printf("2");
case 3: printf("3\n");
default: printf("other\n");
}
return 0;
}
因为没有break,switch满足条件的case以后都会执行,逗号表达式的结果是1x2=2,所以满足case 2,没有 break,所以case 2以后的print也会输出