Dynamic Arrays

For this program assignment I am supposed to create dynamic arrays with initial size of two, and ask the user for input to fill the array. Once the array is filled it should then multiply by two, and copy the old inputs of the old array into the new array, while deleting the old dynamic array. How would I achieve this.

create a separate function that grows and copy the contents of the old array to a new array, the function should return a pointer to the new array you created

tip: you should pass the old array as parameter to the grow function and also you will need a size parameter to signal if the copying of old values should stop

in your main, use a variable that keeps track of the number of input, so you can know when to grow the array

And don't forget to delete [] !
So would this be in a loop so whenever it gets full it will multiply its size by two.
yes, something like that :)) experiment and see what happens
Okay i understand that i need to make a function to test it. The testing function will be pretty much a if function. If size=size then *2 it. But where does the whole deleting the old array come in to play?
deleting the old array should come in the function that grows the array, you should delete the old array after copying the old values to the new array , so no memory leak is made
Topic archived. No new replies allowed.