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
which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?
Why do we need runtime polymorphism in c++?
How is static data member similar to a global variable?
What is the sequence of destruction of local objects?
Is it possible to provide default values while overloading a binary operator?
What is #include iostream?
Explain the use of this pointer?
Do you know the use of vtable?
What is the use of endl?
What jobs can you get with a c++ certification?
Which should be more useful: the protected and public virtuals?
What is the use of bit fields in structure declaration?
What are static member functions?
What are signs of manipulation?
What is the difference between a definition and a declaration?