0 votes
in C Plus Plus by
What is wrong with this code?

T *p = new T[10];

delete p;

1 Answer

0 votes
by

The above code is syntactically correct and will compile fine.

The only problem is that it will just delete the first element of the array. Though the entire array is deleted, only the destructor of the first element will be called and the memory for the first element is released.

Related questions

+1 vote
asked May 30, 2020 in NodeJS Essentials by SakshiSharma
+1 vote
asked Jun 13, 2019 in C Plus Plus by Derya
...