若有以下程序 #include main() { char a[20], b[ ]="The sky is blue."; int i; for (i=0; i

admin2015-07-28  18

问题 若有以下程序
#include
main()
{ char a[20], b[ ]="The sky is blue."; int i;
for (i=0; i<10; i++) scanf("%c", &a);
a=’\0’;
gets(b);
printf("%s%s\n", a,b);
}
执行时若输入:
Fig flower is red. <回车>
则输出结果是( )。

选项 A、Fig flower is red.
B、Fig flower is red.is blue.
C、Fig floweris red.
D、Fig floweris

答案A

解析 for循环是读入10个字符到数组a中,for循环结束后给数组a加上字符串结束符,所以调试时a中的数据为’F,’i’,’g’,’ ’,’f’,’l’,’o’,’w’,’e’,’r’,’’。剩余的字符串由gets()函数输入到数组b中,系统会自动用’’来结束字符串的输入,此时b中的数据为’ ’,’i’,’s’,’r’,’e’,’d’,’. ’,’’,’s’,’ ’,’b’,’l’,’u’,’e’,’.v’,’’。printf输出b时,默认在第一个’’停止,所以输出结果为选项A)。
转载请注明原文地址:https://kaotiyun.com/show/AZJp777K
0

最新回复(0)