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 a static element?
What happens if a pointer is deleted twice?
Const char *p , char const *p What is the difference between the above two?
Can malloc be used in c++?
What is unary operator? List out the different operators involved in the unary operator.
Write a function to perform the substraction of two numbers. Eg: char N1="123", N2="478", N3=-355(N1-N2).
What is virtual destructor? What is its use?
Which c++ operator cannot overload?
How does work in c++?
If a base class is an adt, and it has three pure virtual functions, how many of these functions must be overridden in its derived classes?
Can a function take variable length arguments, if yes, how?
Where can I run c++ program?
What is a pointer how and when is it used?
What is meaning of in c++?
What is recursion?