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
What is exception handling? Does c++ support exception handling?
Can java be faster than c++?
What is const in c++?
What is c++ programming language?
How important is c++?
List the features of oops in c++?
What is function overloading c++?
How do you find out if a linked-list has an end?
Is empty stack c++?
What is the meaning of string in c++?
Explain the use of this pointer?
What is a template in c++?
How should a contructor handle a failure?
Write a Program to find the largest of 4 no using macros.
Is c++ the hardest programming language?