有以下程序 #include<string.h> main() {char p[20]={’a’,’b’,’,’c’,’d’},q[]==="abc",r[]="abcde"; strcat(p,r);strcpy(p+strlen(q),q); prin

admin2016-12-18  17

问题 有以下程序
#include<string.h>
main()
{char p[20]={’a’,’b’,’,’c’,’d’},q[]==="abc",r[]="abcde";
strcat(p,r);strcpy(p+strlen(q),q);
printf("%d\n",strlen(p));}
程序运行后的输出结果是

选项 A、9
B、11
C、6
D、7

答案C

解析 字符串连接函数stxcat(p,r)的功能是把字符数组p[]和r[]连接起来,此时字符数组p[]的有效字符长度为9,再执行strcpy(p+strlen(q),q)字符串复制函数,把字符数组q[]复制到字符数组p[]从p[3]开始到p[5]数组位置中,由于字符数组q[]中的内容为字符串“abc”复制时把字符串结束标志’\null’也复制到字符数组p[]中,这时字符函数strlen(p)返回字符数组p[]的有效字符长度为6。
转载请注明原文地址:https://kaotiyun.com/show/nfDp777K
0

最新回复(0)