C++ Program to copy all elements of an array to another array


In this program, You will learn how to copy all elements of an array to another array in C++.


List is: 1, 2, 12, 23, 24

Copy list is: 1, 2, 12, 23, 24


Example: How to copy all elements of an array to another array in C++

Run it Now
#include<iostream>
using namespace std;

int main() {

    int arr1[10], arr2[10], i, n;

    cout << "Enter Size of an Array :";
    cin>>n;

    cout << "\nEnter Array Elements :";
    for (i = 0; i < n; i++) {
        cin >> arr1[i];
    }

    for (i = 0; i < n; i++) {
        arr2[i] = arr1[i];
    }
    cout << "\nCopy Array List is :";
    for (i = 0; i < n; i++) {
        cout << arr2[i] << " ";
    }

    return 0;
}

Output:

Enter Size of an Array :5
Enter Array Elements :11 22 33 44 55
Copy Array List is :11 22 33 44 55