#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
char *strcpy(char *des,const char *src)
{
assert(des != NULL && src != NULL);
char *temDes = des;
while ((*des++ = *src++) != '\0');
return temDes;
}
int main(void)
{
char a[] = "hello";
char b[] = "world";
char *c = strcpy(a,b);
printf("%s",c);
system("pause");
return 0;
}
如果在main函数中这样写的话:
char *a = "hello";
char *b = "world";
调用
char *c = strcpy(a,b);
是会崩溃的,因为char *a = "hello";是在常量区,只能读取,不能修改,char a[] = "hello";是在栈区,可以读写。