📜  调整动态数组大小 c++ 代码示例

📅  最后修改于: 2022-03-11 14:44:57.547000             🧑  作者: Mango

代码示例1
void resize() {
    size_t newSize = size * 2;
    int* newArr = new int[newSize];

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

    size = newSize;
    delete [] arr;
    arr = newArr;
}