Difference between delete and delete[]?

Answers were Sorted based on User's Feedback



Difference between delete and delete[]?..

Answer / sachin mahajan

When we want to free a memory allocated to a pointer to an
object then "delete" is used.
Ex
int * p;
p=new int;
// now to free the memory
delete p;
But when we have allocated memory for array of objects like
int * p= new int(10); //pointer to an array of 10 integer
then to free memory equal to 10 integers
delete []p;
NOTE: One can free the memory even by "delete p;" But it
will free only the first element memory.


Is This Answer Correct ?    70 Yes 9 No

Difference between delete and delete[]?..

Answer / laxman

delete is only just to delete a variable which is created
by new operator. delete[] , it deletes the array where the
varaialbe points .

Is This Answer Correct ?    24 Yes 8 No

Difference between delete and delete[]?..

Answer / vikas

If p is pointer to an array and is allocated memory on
heap, then delete p would call the destructor of the first
element but will free up the whole block. More info at:

http://www.cppquestions.com/viewtopic.php?f=27&t=13

Is This Answer Correct ?    14 Yes 5 No

Difference between delete and delete[]?..

Answer / namitha

delete is a function used to deallocate the storage space.
delete[] is a function used to deallocate the storage space
of an array.

Is This Answer Correct ?    11 Yes 8 No

Difference between delete and delete[]?..

Answer / sunita shukla

Delete p deallocate memory pointed to by p and delete []p deallocate array. But delete p will delete only p[0]. Other array's Size-1 entries will not be deleted and this memory will leak.

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More C++ General Interview Questions

Who made c++?

0 Answers  


Difference between pass by value and pass by reference?

0 Answers  


Implement strcmp

3 Answers   Bloomberg, Citadel,


What is size of a object of following class? class Foo { public: void foo(){} }

2 Answers   CA,


Who discovered c++?

0 Answers  






Give 10 points of differences between C & C++.

0 Answers   HCL,


What are c++ storage classes?

0 Answers  


How do you declare A pointer to a function which receives nothing and returns nothing

0 Answers  


What is the use of function pointer?

0 Answers  


what is smart pointer & use of the smart pointer ???

2 Answers  


What would happen on forgetting [], while deallocating an array through new?

0 Answers  


What is srand c++?

0 Answers  


Categories