ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  C++ General
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
Difference between delete and delete[]?
 Question Submitted By :: Vasudevan
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Difference between delete and delete[]?
Answer
# 1
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 ?    3 Yes 0 No
Sachin Mahajan
 
  Re: Difference between delete and delete[]?
Answer
# 2
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 ?    2 Yes 0 No
Laxman
 
 
 
  Re: Difference between delete and delete[]?
Answer
# 3
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:

http://www.cppquestions.com/viewtopic.php?f=27&t=13
 
Is This Answer Correct ?    0 Yes 0 No
Vikas
 

 
 
 
Other C++ General Interview Questions
 
  Question Asked @ Answers
 
What is the difference between a copy constructor and an overloaded assignment operator? Microsoft3
Memory is not a constraint. In a single iteration(NOTE: you can't go back), how will you find out the 10th last node/item in a linked list. Goldman-Sachs8
How many lines of code you have written for a single program? BoA1
What is "mutable" keyword?  2
What does '\r' and '\b' mean? Please explain with example.  2
Shall we use 'free' to free memory assigned by new, What are the further consequences?? Symphony4
Is there something that we can do in C and not in C++? Patni6
Is structure can be inherited? HP3
When volatile can be used? Symphony2
Write the program for fibonacci in c++?  3
What are advantages and disadvantages of Design patterns? IBM3
What is difference between initialization and assignment? HP4
class professor {}; class teacher : public virtual professor {}; class researcher : public virtual professor {}; class myprofessor : public teacher, public researcher {}; Referring to the sample code above, if an object of class "myprofessor" were created, how many instances of professor will it contain? a) 0 b) 1 c) 2 d) 3 e) 4 Quark1
What are inline functions? Verizon2
Can we have "Virtual Constructors"? TCS5
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++? Intel1
How do you link a C++ program to C functions?  2
Find the second maximum in an array? HCL2
Difference between Top down and bottom up approaches for a given project ? HP1
How long does this loop run: for(int x=0; x=3; x++) a) Never b) Three times c) Forever Quark9
 
For more C++ General Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com