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

What is the use of setprecision in c++?

544


What are the new features that iso/ansi c++ has added to original c++ specifications?

583


Define virtual constructor.

641


What do you mean by volatile and mutable keywords used in c++?

580


How many types of scopes are there in c++?

578






Do the parentheses after the type name make a difference with new?

647


Are iterators pointers?

677


Will a C compiler always compile C++ code a) Yes b) No c) Only optimized compilers

614


What is a null object in c++?

633


What is a rooted hierarchy?

683


How many different levels of pointers are there?

656


What type of question are asked in GE code writing test based on c++ data structures and pointers?

3509


Discuss the effects occur, after an exception thrown by a member function is unspecified by an exception specification?

637


What language does google use?

588


How many keywords are used in c++?

556