Tuesday, May 18, 2010

delete operator C++


Anything wrong with this code?
T *p = new T[10];
delete p; 


Everything is correct, Only the first element of the array will be deleted”, The entire array will be deleted, but only the first element destructor will be called.



Anything wrong with this code?
T *p = 0;
delete p;



Yes, the program will crash in an attempt to delete a null pointer. 

No comments:

Post a Comment