先看一个例子
void test()
{
int arr[] = {0,1, 2, 3, 4, 5, 6, 7, 8, 9};
size_t size = sizeof(arr)/sizeof(arr[0]);
for (int i = 0;i < size;i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
Memcpy(&arr[4], arr, sizeof(int)*6);
for (int i = 0;i < size;i++)
{
cout<<arr[i]<<" ";
}
}
输出的结果是:
图解输出结果
我们在看看调用Memmove函数输出的结果
void test()
{
int arr[] = {0,1, 2, 3, 4, 5, 6, 7, 8, 9};
size_t size = sizeof(arr)/sizeof(arr[0]);
for (int i = 0;i < size;i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
Memmove(&arr[4], arr, sizeof(int)*6);
for (int i = 0;i < size;i++)
{
cout<<arr[i]<<" ";
}
}
输出结果:
图解输出结果