C语言:模拟实现memcpy
程序员文章站
2022-05-13 16:13:25
#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
#i...
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> #include<assert.h> void *my_memcpy(void *p1,const void *p2, size_t count) { assert(p1); assert(p2); char *dest = (char *)p1; char *src = (char *)p2; char *ret = dest; while (count--) { *dest = *src; src++; dest++; } return ret; } int main() { float arr1[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }; float arr2[10]; int i = 0; int len = sizeof(arr1); float *ret = my_memcpy(arr2, arr1,len ); for (i = 0; i < 9; i++) { printf("%f ", *(ret + i)); } system("pause"); return 0; }