array inversion

Off topic:
1) The array name means the whole array in both cases
a. In the same function value that defines the array, find sizeof(arr), which represents the number of bytes in the entire array
b. In the same function value that defines the array, printf ("%d, %d", &arr, &arr+1 ) here represents the number of bytes of the entire array

2) Inversion of the array
#include <stdio.h>
void Rerves(int *arr,int len ​​)
{
 int tmp;
 for(int i=0;i<len/2;i++) //If len is not divided by 2, it will be exchanged twice, the value will remain the same
 {
  tmp = arr[i];
  arr[i] = arr[len-1-i];
  arr[len-1-i] = tmp;
 }
 for(int i=0;i<len;i++)
 {
   printf("% d\n",arr[i]); //Put the output out, because if you put it in the previous for, only half of the numbers will be output
 }
}
int main()
{
 int arr[]={1,2,3,4,5,6,7,8,9};
 Rerves(arr, sizeof(arr)/sizeof(arr[0]) ); // Used to calculate the number of elements of the array, the byte of an array element arr[0] is 4
 return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325652083&siteId=291194637