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

admin2018-06-28  29

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

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

答案C

解析 strcpy:字符串复制函数;strlen:求字符串长度函数(注意:不包含字符串结束标记字符’\0’);strcat:字符串连接函数。执行完语句strcat(p,r);后,p数组中存储的元素为a,b,c,d,a,b,c,d,e;执行语句strcpy(p+strlen(q),q);得到的结果是将q所指向的字符串复制至p+strlen(q)开始的存储位置,因为strlen的值为3,即p+3开始存储q中的元素,所以执行完strcpy(p+strlen(q),q)语句后,字符数组p[20]的存储元素为a,b,c,
转载请注明原文地址:https://kaotiyun.com/show/2Rxp777K
0

最新回复(0)