Memory overlap with memory alignment

Memory overlap
length of the array of n m data to the front
void the Move (ARR int *, int n, int m)
{
IF (m <0 || = m> = n)
{
return;
}
int * BRR = (int ) the malloc (m the sizeof (int)); // int BRR [m];

int i;
for(i=0;i<m;i++) //将后面的m个数据另外保存
{
	brr[i] = arr[n-m+i];
}

for(i=n-m-1;i>=0;i--)//将数据往后移
{
	arr[i+m] = arr[i];
}

//将brr数据移到arr中
for(i=0;i<m;i++)
{
	arr[i] = brr[i];
}

free(brr);

}

int main()
{
int arr[10] = {1,2,3,4,5,6,7,8,9,10};

Move(arr,sizeof(arr)/sizeof(arr[0]),3);
Show(arr,sizeof(arr)/sizeof(arr[0]));

return 0;

}
Here Insert Picture Description
Memory aligned
address a variety of data to be stored can be divisible by the number of bytes of data per se
Here Insert Picture Description

Published 13 original articles · won praise 3 · Views 629

Guess you like

Origin blog.csdn.net/weixin_43873172/article/details/88580080