C++ Code Example: array in reverse order

The following program outputs an array in reverse order. This is solved with a for-loop. Starting with the last element of the list, each element is output. The step size of the for-loop is -1, until we finally arrive at the first element of the list.

#include <iostream>
using namespace std;

int main () {
    int numbers[] = {1, 2, 3, 4, 5, 6, 7};
    int arrayLength;

    arrayLength = end(numbers) - begin(numbers);

    // print array
    for (int i = 0; i < arrayLength; i++) {
        cout << numbers[i] << " ";
    }
    
    cout << endl;
    
    // print array in reverse order
    for (int i = arrayLength - 1; i >= 0; i--) {
        cout << numbers[i] << " ";
    }

    return 0;
}
Output
1 2 3 4 5 6 7 
7 6 5 4 3 2 1