又是switch 问题。谁可以给下解题思路。

来源:百度知道 编辑:UC知道 时间:2024/05/05 20:32:30
29.有以下程序,若输入为字符s,则程序运行结果为()。
#include ”stdio.h”
main()
{
char ch;
ch=getchar();
switch (ch)
{ case ’a’: printf(”a=%c\n”,ch);
default: printf(”end!\n”);
case ’b’: printf(”b=%c\n”,ch);
case ’c’: printf(”c=%c\n”,ch);
}
}
A.end! B.end! C.有语法错误 D.a=s
b=s end!
c=s

选A啊
end!
b=s
c=s
好好看看书吧,清华大学出版社 谭浩强的书看过了 C语言应该没什么问题的

D
因为s没有找到匹的信息就直接执行了default后面的语句,又因为case语句后面又没有break语句就要输出后面的语句直到结束。

这里有个函数getchar();
运行时需输入参数:s;
则运行结果为A ;
注:本人在tc中运行的。