怎么解啊实在是不会刚刚学c++感觉头快秃了咋算啊快教教我教教我打不出来经常报错怎么办呢
a先自加变为1,然后计算a*b = 2,因此switch中的表达式求值后的结果是2,于是跳去case 2,输出2。但是没有break;所以会接着向后运行case 3,输出3并换行。还是没有break,于是接着执行default子句,输出other。
所以第一行输出23,第二行输出other
#include <stdio.h>
int main() {
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;
}
++a,a的值就是1,然后axb=2,从case 2开始,因为没有break,就是 23,3有\n换行,然后再输出other
你没有贴出来问题啊,
不要急躁,遇到问题先思考,尝试,之后再问,多了就好了
厉害的人都是躺过这坑走出来的