內存重疊拷貝函數 #include<stdio.h> #include<assert.h> void my_memmove(void *p1,void const *p2,size_t count) { char *dest = (char *)p1; char *src = (char *)p2; assert(p1); assert(p2); if((dest > src) && (dest < src +count)) { while(count--) { *(dest + count) = *(src + count); } } else { while(count--) { *dest++ = *src++; } return p1; } } int main() { int arr1[10]={1,2,3,4,5,6,7,8,9,10}; int i = 0; my_memmove(arr1+4,arr1+2,16); for(i=0;i<10;i++) { printf("%d ",arr1[i]); } printf("\n"); return 0; }