Answers for "Resize method in c++ for arrays"

C++
0

Resize method in c++ for arrays

void resize() {
    size_t newSize = size * 2;
    int* newArr = new int[newSize];

    memcpy( newArr, arr, size * sizeof(int) );

    size = newSize;
    delete [] arr;
    arr = newArr;
}
Posted by: Guest on May-14-2021

Browse Popular Code Answers by Language