Hello, my program is currently error free but I must have made a mistake with the pointers or something as it 's crashing when compiling. The program is supposed to have a function that takes two parameters, a reference to a pointer that is a dynamically allocated array of doubles. The function should replace the array with one that is twice as large. It also needs to prevent memory leaks.
void growArray(double*& oldArray, int size)
{
int newSize = size * 2; // calc new size
double* newArray = newdouble[newSize]; // create new array
// copy old array to new array
for (int i = 0; i < size; i++)
{
newArray[i] = oldArray[i];
}
// fill the remaining spots
for (int i = size; i < newSize; i++)
{
newArray[i] = (i + 1) * 2;
}
delete [] oldArray; // get rid of the old one
oldArray = newArray;
}