How to delete a dynamic array?

前端 未结 1 1013
醉话见心
醉话见心 2021-01-29 14:01

I build an array with help with this question: How do I declare a 2d array in C++ using new?
Now, my question is, how do I delete it?
I know it\'s a for loo

1条回答
  •  礼貌的吻别
    2021-01-29 14:28

    The same way you created it. If you have a 2D array, yourArray, that has rows number of rows.

    for (int i = 0; i < rows; ++i)
    {
        delete [] yourArray[i];
    }
    delete [] yourArray;
    

    0 讨论(0)
提交回复
热议问题