C语言库函数memcpy函数模拟实现
#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);
((char*)dest)++; ((char*)src)++;
}
return ret;
}
void test()
{
int arr1[] = { 1, 2, 3, 4, 5 };
int arr2[5] = { 0 };
my_memcpy(arr2, arr1, sizeof(arr1));
for (int i = 0; i < 5; i++)
printf("%d ", arr2[i]);
}
int main()
{
test();
共有 0 条评论