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 the use of setprecision in c++?
What are the new features that iso/ansi c++ has added to original c++ specifications?
Define virtual constructor.
What do you mean by volatile and mutable keywords used in c++?
How many types of scopes are there in c++?
Do the parentheses after the type name make a difference with new?
Are iterators pointers?
Will a C compiler always compile C++ code a) Yes b) No c) Only optimized compilers
What is a null object in c++?
What is a rooted hierarchy?
How many different levels of pointers are there?
What type of question are asked in GE code writing test based on c++ data structures and pointers?
Discuss the effects occur, after an exception thrown by a member function is unspecified by an exception specification?
What language does google use?
How many keywords are used in c++?