64,682
社区成员
发帖
与我相关
我的任务
分享
int main(){
char str1[]="I love CHINA!",str2[20],* p1,* p2;
p1=str1;p2=str2; //将p1和p2指针分别指向str1和str2首地址
for(;* p1!='\0';p1++,p2++) //如果p1所指的当前字符不是'\0',就循环
* p2=* p1; //逐字节拷贝
* p2='\0'; //在p2所指的str2字符串末尾补上'\0'
p1=str1; //将p1和p2重新指回字符串首地址
p2=str2;
cout<<"str1 is:"<<p1<<endl;
cout<<"str2 is:"<<p2<<endl;
}