分析下列程序输出

#include<iostream>
#include<string.h>
using namespace std;
int main() {
    char p1[15]="abcd",*p2="ABCD",str[50]="xyz";
    strcpy(str+2,strcat(p1+2,p2+1));
    cout<<str;
    return 0;
}

程序输出xycdBCD

 

分析:

strcat(p1+2,p2+1); //返回以p1+2为首的字符串,即"cdBCD" 
strcpy(str+2,strcat(p1+2,p2+1)); //将"cdBCD"copy到str+2位置上,并覆盖后面的内容,此时str为"xycdBCD" 
posted on 2017-07-24 09:45  王小东大将军  阅读(310)  评论(0编辑  收藏  举报