#include <iostream>
#include <string>
using std::cout;
using std::endl;
void* mymencpy(void* dest, void* src, size_t num) {
char* d = (char*)dest;
char* s = (char*)src;
while (num--) {
*(d++) = *(s++);
}
return d;
}
void* mymenmove(void* dest, void* src, size_t num) {
char* d = (char*)dest;
char* s = (char*)src;
if (s > d) {
while (num--) {
*(d++) = *(s++);
}
}
else {
d += num - 1;
s += num - 1;
while (num--)
{
*(d--) = *(s--);
}
}
return d;
}
int main() {
int a[] = { 1,2,3,4,5 };
int b[5];
//mymencpy(a+1, a, 16);
mymenmove(a + 1, a, 16);
for (auto s : a) {
cout << s;
}
cout << endl;
}
参考博客:memmove 和 memcpy的区别以及处理内存重叠问题
标签:src,--,void,C++,char,dest,num,调试程序,memcpy From: https://www.cnblogs.com/fly-smart/p/18010839