memcpy 内存拷贝 不同于strcpy只局限于字符串的拷贝
#include #include#include void* my_memcpy(void* dest,const void* src, size_t num) { assert(dest != NULL); assert(src != NULL);//保证指针的有效性 void* ret = dest;//保留起始位置 作为函数返回值 while(num--) { *(char*)dest = *(char*)src; dest = (char*)dest + 1; src = (char*)src + 1; } return ret; } int main() { int arr1[] = {1,2,3,4,5,6}; int arr2[10] = {0}; int i = 0; int sz = sizeof(arr1)/sizeof(arr1[0]); my_memcpy(arr2,arr1,sizeof(arr1)); for(i=0;i 欢迎分享,转载请注明来源:内存溢出
评论列表(0条)