例如 我们要把字符串"hello"复制到数组arr[20]中去时,你会怎么操作;
首先 arr = "hello";//是错误的
arr数组名是首元素的地址,是个地址常量,是个编号;难道把hello放到这个编号上?
答案应该是放到编号所指向的空间中去;

其中 destination是目标空间的地址,source是源空间的地址
把源指针指向的空间的数据拷贝到目的地指针指向的空间中去;
char* p = "hello";//把首字符的地址放到p中,p就指向了这个字符串;
strcpy(arr,"hello");
"hello"传参的时候传过去的是首字符'h'的地址,传给了source;其中destination指向了arr[20]整个数组,source指向了hello中'h'的地址;然后把source指向的hello拷贝放到destination指向的arr[20]中去;
- char *my_strcpy(char *destination, const char*source)
- {
- char *ret = destination;
- assert(destination != NULL);
- assert(source != NULL);
- while((*destination++ = *source++))
- {
- ;
- }
- return ret;
- }