C++ Program to Copy the Contents of One Array Into Another in the Reverse Order

Last Updated : 21 Aug, 2026

Copying an array in reverse order means storing its elements in a second array from the last element to the first.
This approach preserves the original array while creating a reversed copy.

  • Stores the elements of the original array in reverse order in a new array.
  • Uses an additional array, so the original array remains unchanged.

Examples:

Input: arr[] = {1, 2, 3, 4, 5}
Output: copyArr[] = {5, 4, 3, 2, 1}

Explanation: The last element 5 is copied first, followed by 4, 3, 2, and 1.

Input: arr[] = {10, 20, 30, 40, 50}
Output: copyArr[] = {50, 40, 30, 20, 10}

Explanation: Each element is copied from the original array to the new array in reverse order.

Approach

The idea is to traverse the original array from left to right and place each element at the corresponding position from the end in the new array.

For an array of size n, the element at index i in the original array is copied to index n - i - 1 in the new array.

Steps:

  1. Create a new array of the same size as the original array.
  2. Traverse the original array from index 0 to n - 1.
  3. Copy arr[i] to copyArr[n - i - 1].
  4. Print the original and reversed arrays.
C++
#include <iostream>
#include <vector>
using namespace std;

// Function to print an array
void printArray(const vector<int>& arr)
{
    for (int x : arr)
        cout << x << " ";
}

int main()
{
    vector<int> arr = {1, 2, 3, 4, 5};
    int n = arr.size();

    vector<int> copyArr(n);

    // Copy elements in reverse order
    for (int i = 0; i < n; i++)
        copyArr[n - i - 1] = arr[i];

    cout << "Original array: ";
    printArray(arr);

    cout << "\nResultant array: ";
    printArray(copyArr);

    return 0;
} 

Output
Original array: 1 2 3 4 5 
Resultant array: 5 4 3 2 1 

Explanation: For the input array {1, 2, 3, 4, 5}, the elements are copied as follows:

  • arr[0] = 1 -> copyArr[4] = 1
  • arr[1] = 2 -> copyArr[3] = 2
  • arr[2] = 3 -> copyArr[2] = 3
  • arr[3] = 4 -> copyArr[1] = 4
  • arr[4] = 5 -> copyArr[0] = 5

Therefore, the resultant array becomes {5, 4, 3, 2, 1}.

Using vector makes the implementation standard and portable C++, unlike variable-length arrays such as int copyArr[n], which are not part of standard C++.

Comment