user1235183
user1235183

Reputation: 3072

How to delete 2d array?

How do I delete this allocated pointer?

int (*foo)[4] = new int[100][4];

Is it just :

delete[] foo;

Upvotes: 1

Views: 129

Answers (1)

Vlad from Moscow
Vlad from Moscow

Reputation: 310930

As you have allocated an array you have to use operator delete[]

delete []foo;

That it would be more clear you can rewrite the code snippet the following way

typedef int T[4];

T *foo = new T[100];

delete []foo;

Upvotes: 5

Related Questions