C++ concatenate two int arrays into one larger array

前端 未结 6 2130
小蘑菇
小蘑菇 2020-12-08 16:20

Is there a way to take two int arrays in C++

int * arr1;
int * arr2;
//pretend that in the lines below, we fill these two arrays with different
//int values
         


        
6条回答
  •  悲哀的现实
    2020-12-08 16:37

    for (int i = 0; i< arraySize * 2; i++)
    {
        if (i < aSize)
        {
            *(array3 + i) = *(array1 + i);
        }
        else if (i >= arraySize)
        {
            *(array3 + i) = *(array2 + (i - arraySize));
        }
    
    }
    

    This might help you along, it doesn't require vectors. I had a similar problem in my programming class. I hope this helps, it was required that I used pointer arithmetic. This assumes that array1 and array2 are initialized dynamically to the size "aSize"

提交回复
热议问题