#include <string.h>
#include <stdio.h>
int main()
{
char a[30] = "string (a)";
char b[30] = "hi\0zengxiaolong";
int i;
strcpy(a, b); //a[30] = "hi\0ing (a)"
printf("strcpy():");
for(i = 0; i < 30; i++)
printf("%c", a[i]); //hi ing (a)
memcpy(a, b, 30); //a[30] = "hi\0zengxiaolong"
printf("\nmemcpy():");
for(i = 0; i < 30; i++)
printf("%c", a[i]); //hi zengxiaolong
printf("\n i = %d\n", i); //30
}
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240825082459112-376424429.jpg)