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
Define pre-condition and post-condition to a member function in c++?
what is COPY CONSTRUCTOR and what is it used for?
What is a breakpoint?
What is late binding c++?
Explain the difference between c++ and java.
Is c++ a good beginners programming language?
When is dynamic checking necessary?
What is wrapper class in c++?
How do I run c++?
How can I disable the "echo" feature?
Why is c++ still best?
How is static data member similar to a global variable?
what is a reference variable in C++?
What is #include iostream h in c++?
By using c++ with an example describe linked list?