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
How a pointer differs from a reference?
What are guid? Why does com need guids?
Is it possible to get the source code back from binary file?
What is an iterator?
What is the use of endl in c++?
When we use Abstract Class and when we use Interface?where we will implement in real time?
What is virtual destructor ans explain its use?
What are static member functions?
What is a forward referencing and when should it be used?
What does count ++ do in c++?
Tell me an example where stacks are useful?
Keyword mean in declaration?
Can comments be longer than one line?
What are the two types of comments?
How can I improve my c++ skills?