Write a C++ program to reverse an Array.

Example:

To reverse an array we can use the swapping method. In the swapping method, we will swap the first element with the last, second element with the second last and so on.

So to do this, we will have to loop through the array from start to mid (size/2) and swap the front element array[i] with the backward element array[size-i-1].

See the full implementation in C++ below.

Reverse Array in C++ using Swapping

Output

Array reverse result

In the above method, we have not used any extra array to reverse an Array in C++, hence the method is quite space-efficient. Suggest in the comment box, if you know or want to get your method added in the post.

Leave a Reply

Close Menu