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
Write about the stack unwinding?
What are the differences between java and c++?
What is a literal in c++?
What does n mean in c++?
When there is a global variable and local variable with the same name, how will you access the global variable?
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?
What is the size of a vector?
What is #include ctype h in c++?
What is a syntax in c++?
what Is DCS ? what i will get benefit when i did?
Which is the best c++ compiler for beginners?
Is c++ the hardest programming language?
Which of the following is evaluated first: a) && b) || c) !
What is the best book for c++ beginners?
What is virtual destructor? What is its use?