下列程序的输出结果是______。 include<stdio.h> main() { int x=
下列程序的输出结果是______。 include<stdio.h> main() { int x=1,y=1,a=1,b=1; switch(x) { case 1: switch(y) { Case0:a++;break; case 1:b++;break; } case2: a++;b++;break; } printf("a=%d,b=%d/n",a,b); }
请帮忙给出正确答案和分析,谢谢!
参考解答
正确答案:a=2b=3
分析程序,程序从x=1语句开始执行,之后执行第一个switch语句,switch(x)=switch(1),所以执行case1,case1语句中包含一个复合switch语句;这时执行第二个switch语句,此时y=1,所以switch(y)=switch(1),因此执行case1,将b加1,得到b=2,遇到break语句,退出第二个switch语句,则整个case1的复合语句执行完毕,由于在这个case1的后面没有break语句使其退出第一个switch语句,所以接着执行下列的case2后面的语句,即将a、b各加1,得到a=2,b=3。
相似问题
以下程序的输出结果是【 】。 define MCNA(m)2*m define MCNB(n m)
以下程序的输出结果是【 】。 define MCNA(m)2*m define MCNB(n, m)2*MCRA(n)+m define f(x)(x*x) main() { int i=2, j=3; printf( "% d n ", MCRB(j, MCRA(i))); }请帮忙给出正确答案和分析,谢谢!
下面程序的功能:将字符数组a中下标值为偶数的元素从小到大排列 其他元素不变。请填空。 include
下面程序的功能:将字符数组a中下标值为偶数的元素从小到大排列,其他元素不变。请填空。 include<stdio h> include<string h> main() { ch
有以下程序: void f(int*x iht * y) { int t; t=*x;*x;=*y;
有以下程序: void f(int*x,iht * y) { int t; t=*x;*x;=*y;*y=t; } main() { int a[8]={1,2,3,4,5,6,7,8},i,*p,*q; p=a;q=&a[7]; while(
以下程序的运行结果是【 】。 include <stdio.h> main() { int x=1
以下程序的运行结果是【 】。 include <stdio.h> main() { int x=1,y=0,a=0,b=0; switch(x) { case 1: switch(y) { case 0:a++
若a=1 b=2 则表达式!(x=a)‖(y=b)&&0的值是______。请帮忙给出正确答案和分析
若a=1,b=2,则表达式!(x=a)‖(y=b)&&0的值是______。请帮忙给出正确答案和分析,谢谢!
