Search code examples
c++memory-leaksdelete-operator

How can i delete a pointer to array in C++


I am wondering how can i use the delete operator if I want to delete an array initialized like this:

int (*my_ptr)[10] = new int[3][10];

This seems invalid:

delete[][]

Solution

  • new int[3][10] is simply creation of a dynamic array whose elements are themselves arrays. This is deleted in the same way as all dynamic arrays: delete[].