Search
 
SCRIPT & CODE EXAMPLE
 

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;
}
Comment

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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: count sort algorithm 
Cpp :: inheritance in c++ 
Cpp :: find function in c++ 
Cpp :: c++ initialise array 
Cpp :: system cpp 
Cpp :: c++ print 
Cpp :: string comparison c++ 
Cpp :: c++ for each loop 
Cpp :: pass map as reference c++ 
Cpp :: Fisher–Yates shuffle Algorithm c++ 
Cpp :: c++ template vs code 
Cpp :: how to empty a std vector 
Cpp :: get std string from file 
Cpp :: how to remove the scroll bar in pyqt6 
Cpp :: c++ get active thread count 
Cpp :: how to declare a 2d vector stack 
Cpp :: c++ check that const char* has suffix 
Cpp :: bubble sort c++ 
Cpp :: how to make randomizer c++ 
Cpp :: c ++ program to insert into hashmap 
Cpp :: pow without math.h 
Cpp :: c++ if else example 
Cpp :: shift element to end of vector c++ 
Cpp :: find maximum sum of circular subarray 
Cpp :: floor and ceil in cpp 
Cpp :: print all subsequences 
Cpp :: is there garbage collection in c++ 
Cpp :: rgb type def 
Cpp :: c++ calling variable constructor 
Cpp :: solve problem of getline 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =