Hey, I need a function that virtually increase the size of an array, by creating a new array with the size of the old array plus the default array size and copying the content of the old array to the new array, finally returning the new array. This is a function that receives an old array, the size of the old array, and the default size.

so what I pictured is something like this..

int * ResizeArray(int array[], int size, int SIZE){
int * array2;
array2 = new int ;

for(int i = 0; i < size + SIZE; i++)
array2 = array;

return array2;

Well.. I'm still new at this C++ programing stuff and am not sure about anything..

Any hint or little help would be appreciated. thanks :$

8 Years
Discussion Span
Last Post by Fbody

It looks good conceptually, but I'm a little concerned about the structure of that for loop. It overruns the boundaries of the original array.

I think you should probably use the first for loop to copy the data, then use a second for loop to finish initializing the rest of the new (larger) array. Either that or put an if in there that says if (i >=size) you store zero (0) instead of copying from the (now overrun) original array.

Edited by Fbody: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.