Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #double #array #size
ADD COMMENT
Topic
Name
4+7 =