basics · beginner · ~15 min

Reverse an array in place

Swap from both ends toward the middle.

Challenge

Implement void reverse_array(int *a, int n) reversing the first n elements in place using two indices.

Starter code

void reverse_array(int *a, int n) {
    /* TODO */
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.