Answers for "double array size c++"

C++
0

double array size c++

void enlarge(int *& array, int size) {
//                ^
// Use a reference to a pointer.

    int *dbl = new int[size*2];
    for (int i = 0; i < size; i++) {
    //                  ^
    // Iterate up to size, not size*2.
        dbl[i] = array[i];
    }
    delete[] array;
    //    ^
    // Use delete[], not delete.
    array = dbl;
}
Posted by: Guest on October-28-2021

Browse Popular Code Answers by Language