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
Array base access faster or pointer base access is faster?
What is the role of static keyword for a class member variable?
What is a node class in c++?
How long it will take to learn c++?
Can union be self referenced?
Can static member variables be private?
Will the following program execute?
Is recursion allowed in inline functions?
What is the difference between function overloading and operator overloading?
What is the benefit of learning c++?
How would you implement a substr() function that extracts a sub string from a given string?
What is the difference between struct and class?
What is the best c c++ compiler for windows?
What are the steps in the development cycle?
What is c++ in english?