Difference between delete and delete[]?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is exception handling? Does c++ support exception handling?

589


Can java be faster than c++?

669


What is const in c++?

596


What is c++ programming language?

577


How important is c++?

529






List the features of oops in c++?

572


What is function overloading c++?

570


How do you find out if a linked-list has an end?

647


Is empty stack c++?

519


What is the meaning of string in c++?

569


Explain the use of this pointer?

634


What is a template in c++?

635


How should a contructor handle a failure?

688


Write a Program to find the largest of 4 no using macros.

580


Is c++ the hardest programming language?

637