#include <stdio.h> #include <stdlib.h> #include <assert.h> void *my_memmove(void *p1, const void *p2, size_t count) { assert(p1); assert(p2); char *dest = (char*)p1; char *src = (char*)p2; dest = dest + 16; src = src + 8; if ((src <= dest) && (dest <= (src + count))) { while (count--) { *(dest + count) = *(src + count); } } else { while (count--) { *dest++ = *src++; } } return p1; } int main() { int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; size_t count =16; int *ret=my_memmove(arr, arr, count); int i = 0; for (i = 0; i < 10; i++) { printf("%d ", *(ret+i)); } system("pause"); return 0; }
【C语言】【面试题】【笔试题】模拟实现数据库中memmove函数
原文地址:http://10740329.blog.51cto.com/10730329/1714513