如何将两个指针数组一起添加?

时间:2015-10-30 18:44:55

标签: c++ arrays pointers addition

如果我有指针数组AB,我怎样才能获得C = A + B

A[2] = apple;orange;
B[3] = grapes;lemons;banana;

1 个答案:

答案 0 :(得分:0)

Initialize a new array with the size of A + B, then copy the elements over.

This is because when you initialize an array with a fixed size, it stays that fixed size. The only way to sum up two arrays is to first allocate a new array, or if your original array is big enough, just append the second one to the first. This also happened to be how your usual ArrayList resizes when it reaches full capacity.