Difference between delete and delete?
Answers were Sorted based on User's Feedback
Answer / sachin mahajan
When we want to free a memory allocated to a pointer to an
object then "delete" is used.
int * p;
// now to free the memory
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
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|
Answer / laxman
delete is only just to delete a variable which is created
by new operator. delete , it deletes the array where the
varaialbe points .
|Is This Answer Correct ?||24 Yes||8 No|
Answer / vikas
If p is pointer to an array and is allocated memory on
heap, then delete p would call the destructor of the first
element but will free up the whole block. More info at:
|Is This Answer Correct ?||14 Yes||5 No|
Answer / namitha
delete is a function used to deallocate the storage space.
delete is a function used to deallocate the storage space
of an array.
|Is This Answer Correct ?||11 Yes||8 No|
Answer / sunita shukla
Delete p deallocate memory pointed to by p and delete p deallocate array. But delete p will delete only p. Other array's Size-1 entries will not be deleted and this memory will leak.
|Is This Answer Correct ?||3 Yes||0 No|
what is the difference between overloading & overriding? give example.
Why is it necessary to use a reference in the argument to the copy constructor?
What is the difference between the parameter to a template and the parameter to a function?
What are proxy objects in c++?
what is polymorphism?
What are the total number of lines written by you in C/C++? What is the most complicated or valuable program written in C/C++?
Describe private, protected and public?
what are Access specifiers in C++ class? What are the types?
which operator is used for performing an exponential operation a) > b) ^ c) none
What is c++ and its uses?
Difference between overloading vs. Overriding
Write an algorithm that determines whether or not an almost complete binary tree is a heap.