Difference between delete and delete[ ]
delete and delete[ ]
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Apr 29, 2014, 5:21 AM EDT
In C++, delete is used to remove an object from memory which was created using new and delete[] is used to remove an array object which was created using new[].
Abhay ShankerRank #375 · 6.7K reputationPosted Apr 29, 2014, 6:55 AM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted Apr 29, 2014, 9:31 PM EDT
int *pi = new int; // allocates a single integer
int *pi_array = new int[10]; // allocates an array of 10 integers
delete pi;
pi = 0;
delete [] pi_array;
pi_array = 0;