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

which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?

951


Why do we need runtime polymorphism in c++?

748


How is static data member similar to a global variable?

826


What is the sequence of destruction of local objects?

722


Is it possible to provide default values while overloading a binary operator?

994


What is #include iostream?

973


Explain the use of this pointer?

887


Do you know the use of vtable?

852


What is the use of endl?

737


What jobs can you get with a c++ certification?

792


Which should be more useful: the protected and public virtuals?

772


What is the use of bit fields in structure declaration?

731


What are static member functions?

805


What are signs of manipulation?

820


What is the difference between a definition and a declaration?

802