How to output a one-dimensional array in reverse order …

In C language, a common method to reverse output a one-dimensional array is by using loops to iterate through the array.

#include <stdio.h>

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    int length = sizeof(arr) / sizeof(arr[0]);

    // 逆序输出
    for (int i = length - 1; i >= 0; i--) {
        printf("%d ", arr[i]);
    }

    return 0;
}

The resulting output is: 5 4 3 2 1.

First, the length of the array can be obtained using the sizeof() function, and then a for loop can be used to iterate through the array starting from the last element, decrementing i each time and outputting the corresponding array element.

bannerAds