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


Please Help Members By Posting Answers For Below Questions

Write about the stack unwinding?

624


What are the differences between java and c++?

528


What is a literal in c++?

564


What does n mean in c++?

628


When there is a global variable and local variable with the same name, how will you access the global variable?

616






How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Why is it difficult to store linked list in an array?how can you find the nodes with repetetive data in a linked list?

610


What is the size of a vector?

575


What is #include ctype h in c++?

663


What is a syntax in c++?

603


what Is DCS ? what i will get benefit when i did?

1829


Which is the best c++ compiler for beginners?

554


Is c++ the hardest programming language?

634


Which of the following is evaluated first: a) && b) || c) !

1799


What is the best book for c++ beginners?

566


What is virtual destructor? What is its use?

573