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++.


#include<iostream>
using namespace std;

int main() {
   //Statement
}

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

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

#include<iostream>
using namespace std;

int main() {

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

    cout << "Enter size of an array:";
    cin>>n;

    cout << "Enter array elements:";
    for (i = 0; i < n; i++) {
        cin >> arr1[i];
    }

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

    return 0;
}

Output:

Enter size of an array:5
Enter array elements:10 20 30 40 50
Copy Array List is:10 20 30 40 50