One, standard switching mode
/****
* Standard switching mode
* Implement the inverse of the array, the principle is the array of the end-to-end elements to Exchange
***/
#define N 5;
int main () {
int Array[n] = {15,20,25,30,35}
int temp; Declaring temporary variables
int i;
for (i = 0;i<n/2;i++) {
The first and second values are exchanged with the N-i-1 value
temp = Array[i];
Array[i] = array[n-i-1];
Array[n-i-1] = temp;
}
printf ("Reverse: \ n");
for (i = 0;i < n;i++) {
printf ("%d\t", * (array + i));
}
}
Second, the pointer Exchange Mode
/****
* Pointer Exchange Mode
* Implement the inverse of the array, the principle is the array of the end-to-end elements to Exchange
***/
#define N 5;
int main () {
int Array[n] = {15,20,25,30,35}
int temp; Declaring temporary variables
int i;
int *ptr_array_start = array;
int *ptr_array_end = array + N-1;
while (Ptr_array_start>=ptr_array_end) {
Swap, the pointers are updated separately
temp = *ptr_array_start;
*ptr_array_start = *ptr_array_end;
*ptr_array_end = temp;
First element pointer to move backwards
ptr_array_start++;
End element pointer to move forward
ptr_array_end--;
}
printf ("Reverse: \ n");
for (i = 0;i < n;i++) {
printf ("%d\t", * (array + i));
}
}
C Array Reverse order