将两个字符串合并为一个字符串并且输出

字符串特点:以’\0’结尾

#include<stdio.h>
#include<string.h>
//将两个字符串合并为一个字符串并且输出
int main(void)
{
	char str1[20] = {"Hello "};
	char str2[20] = {"World "};
	
	char *p1,*p2;
	p1 = str1;
	p2 = str2;
	
	//指针p1遍历到str1的最后一个字符
	while(*p1!='\0') //  注意是'\0'
		p1++;
	
	while(*p2!='\0')
	{
		*p1++ = *p2++; //已证明地址有改变
		printf("%p  ",p2);
	
	}

	printf("%s\n",str1);	
	
	return 0;
}


    原文作者:夜星辰2022
    原文地址: https://blog.csdn.net/weixin_37787043/article/details/78555311
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞