Concatenation of an array in C++

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int arr_size1 = 4;
    int arr_size2 = 5;
    int arr1[arr_size1] = {1, 2, 3, 4};
    int arr2[arr_size2] = {5, 6, 7, 8, 9};

    int concat_array[arr_size1 + arr_size2];
    copy(arr1, arr1 + arr_size1, concat_array);
    copy(arr2, arr2 + arr_size2, concat_array + arr_size1);
    for (int i = 0; i < arr_size1 + arr_size2; i++)
    {
        cout << concat_array[i] << " ";
    }
    cout << endl;

    return 0;
}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *