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.
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:


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

What is Destructor in C++?

0 Answers  

what is multi-threading in C++?

0 Answers  

Can we use this pointer in a class specific, operator-overloading function for new operator?

0 Answers  

What does the following do: for(;;) ; a) Illegal b) Loops forever c) Ignored by compiler...not illegal

0 Answers  

What happens if a pointer is deleted twice?

0 Answers   Flextronics,

What new()is different from malloc()?

0 Answers  

What is isdigit c++?

0 Answers  

Can we distribute function templates and class templates in object libraries?

0 Answers  

What are the advantages of using const reference arguments in a function?

0 Answers  

Can char be a number c++?

0 Answers  

Given the following seqment of code containing a group of nested if instructions: y = 9; if ((x==3) || (x == 5)) y++; else if (x == 2) y *= 2; else if (x == 4 ) y-= 7; else y = 8; Enter a segment of code (without any IF statements) that does exectly the same thing using the switch structure.

1 Answers  

Differentiate between a copy constructor and an overloaded assignment operator.

0 Answers