Consider following code:
typedef SomeType type_t[2];
SomeType * arr1 = new type_t; //new or new[] ???
type_t * arr2 = new type_t[3]; //new or new[] ???
According standard which version of new
will be called in 1-st and 2-nd cases ( new
or new[]
) and how to delete arr1
and arr2
(with delete
or delete[]
) ?
First case allocates a one-dimensional array, second case a two-dimensional array. Both of them must be released via delete[]
, otherwise you will get undefined behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With