Categories

Jun 11 in C++

Q: What is wrong with this code?

T *p = new T[10];

delete p;

1 Answer

Jun 11

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.

Click here to read more about C++
Click here to read more about Insurance

Related questions

Madanswer
Jun 13, 2019 in C++
Jun 13, 2019 in C++
Jun 13, 2019 in C++
...