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

Viewed 72

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[][]
2 Answers

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[].

my_ptr is an array of 3 elements. Each element is an int[10] type.

You call delete[] my_ptr; to delete those 3 elements.

Related