#include<stdio.h>
int main(void)
{
char s1[100] = "hello";
char s2[100] = "world";
char *p1;
p1 = s1;
int len = 0;
while (*p1)
{
p1++; //注意这一个一定需要,因为指针开始指向首地址,所以所对应的不为0,如果指针不移动
//while永远为真
len++;
}
printf("len=%d\n",len);
//----------------------------------------
char *p2;
*p1++ = ' ';
p2 = s2;
int len2 = 0;
while (*p2)
{
*p1++ = *p2++;
}
printf("%s\n", s1);
system("pause");
return 0;
}
结果:
len=5
hello world
请按任意键继续. . .
注意:
数组或者字符串的首地址和数组名的区别联系。
弄清楚指针的指向,知道最后为空,也是循环退出的条件
将第一个的最后地址与第二个数组首地址对应,这样以来就可以实现将第二个数组复制到第一个数组中了。