C/C++ Arena

Step 5 of 6

Modify an array in a function

Your turn: write void reverse(int a[], int n) that reverses the array in place (no second array).

Swap the first and last element, then the second and second-to-last, and so on until the middle.

int tmp = a[i];
a[i] = a[j];
a[j] = tmp;

Previous: Arrays as parameters Next: 2D arrays