若有以下程序 #include main() {chara[20],b[]="Theskyisblue.";inti; for(i=0;i<7;i++)scanf("%c",&b[i]); gets(a);printf("%s%s\n",a,b); } 执

admin2015-07-31  17

问题 若有以下程序
#include
main()
{chara[20],b[]="Theskyisblue.";inti;
for(i=0;i<7;i++)scanf("%c",&b);
gets(a);printf("%s%s\n",a,b);
}
执行时若输入:(其中表示回车符)
Figflowerisred.
则输出结果是

选项 A、wer is red.Fig flo is blue.
B、wer is red.Fig flo
C、wer is red.The sky is blue.
D、Fig flower is red.The sky is blue.

答案A

解析 程序首先初始化字符数组b[],执行for循环语句,循环变量i的取值范围从0到6。在for循环语句中通过scanf函数将从键盘上输入的数据输入到b[ ]中,即b的值为Fig flo is blue.。退出for循环语句,执行语句gets(a); ,gets()函数的调用形式为:gets(str_adr),其中str_adr是存放输入字符串的起始地址,可以是字符数组名、字符数组元素的地址或字符指针变量。gets函数用来从终端键盘读入字符串(包括空格符),直到读入一个换行符为止,即a的值为wer is red.。因此A选项正确。
转载请注明原文地址:https://kaotiyun.com/show/ABDp777K
0

最新回复(0)