如果我有指针数组A
和B
,我怎样才能获得C = A + B
?
A[2] = apple;orange;
B[3] = grapes;lemons;banana;
答案 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.