作业帮 > 综合 > 作业

其中的 *p2=*p1; *p2='\0'; 作用是什么?

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/30 00:57:14
其中的 *p2=*p1; *p2='\0'; 作用是什么?
#include "stdafx.h"
#include
using namespace std;
int _tmain(int argc,_TCHAR* argv[])
{
\x05char str1[]="i love china!",str2[20],*p1,*p2;
\x05p1=str1;p2=str2;
for(;*p1!='\0';p1++,p2++)
\x05\x05*p2=*p1;
\x05*p2='\0';
\x05p1=str1;p2=str2;
\x05cout
*p2=*p1; :
把str1[](*p1指向str1[])中的相应位上的字符赋值给str2(*p2指向str2[])
*p2='\0':
因为经过(p2++)此时*p2的值指向str2的末尾
'\0'标记str2结束,就像句号一样,是一位字符串数组更规范