GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 26 of 203    Print  
what is defference between constructor and destructor

  
Total Answers and Comments: 7 Last Update: January 17, 2009     Asked by: anil_mca 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: jyotsna
 
Constructor is a member of the class. Constructor is cerated automatically when class is called. Using construtor we can allocate memory.

Destructor is used for deallocate(release) the memory.

Above answer was rated as good by the following members:
kiranmayijosyula, uday.learn
September 15, 2005 07:49:31   #1  
sumanjit        

RE: what is defference between constructor and destruc...
Constructor is called when a object is createdand Destructor is called when object goes out of scopeConstructor. is used to initilize the valuesDestructor. is uised to free the memory --
 
Is this answer useful? Yes | No
March 05, 2006 00:00:26   #2  
priya        

RE: what is defference between constructor and destruc...
constructor: it is used to construct the object of the class.it is called when object of the first class is instansiated.destructor: it is used while destroying the object.it is called automatically when close braces is encontered.
 
Is this answer useful? Yes | No
April 15, 2006 05:30:44   #3  
nitin_chawda Member Since: April 2006   Contribution: 4    

RE: what is defference between constructor and destruc...

constructor is the memeber function of the class which has the same name as that of class and it is invoked whenever the class object is instantiated.

destructor is also the member function of same class name and has ~ operator when ever declared in the function and it is used to destruct the object which has been constructed whenever we want to destroy it..


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 07, 2007 03:40:01   #4  
jyotsna        

RE: what is defference between constructor and destruc...
Constructor is a member of the class. Constructor is cerated automatically when class is called. Using construtor we can allocate memory.

Destructor is used for deallocate(release) the memory.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
August 03, 2008 07:07:55   #5  
YaelG Member Since: July 2008   Contribution: 1    

RE: what is defference between constructor and destructor
Both Constructor and Destructor are member functions of the class. Both are made by the language defaultly and can be override by the programmer. The constructor is being called when a new object of the class is created- it can be used to initiate members to call functions and what ever is needed when an instance of the class is being made. The destructor is a function that is responsible for avoiding memory leak when deleteting an object. It's important to put a virtual befor constructors of base classes in order to avoid memory leak.
 
Is this answer useful? Yes | No
August 08, 2008 06:33:10   #6  
vsvraju Member Since: August 2008   Contribution: 5    

RE: what is defference between constructor and destructor
Constructor builds the object from the scratch where as destrcutor give the object its last rights (like for getting back the allocated memory). Constructor gets called when the object was created and destructor gets called automatically when the object goes out of scope.
 
Is this answer useful? Yes | No
January 17, 2009 20:35:12   #7  
rlee2008 Member Since: January 2009   Contribution: 1    

RE: what is defference between constructor and destructor

A constructor of a class is mainly responsibly for turning the raw memory allotted to an object into a usable object.
DEFAULT CONSTRUCTOR:
The default constructor is a constructor that takes no argument.
Part::Part()
String() and String(const char* str) can be combined into a single constructor that has a default argument: String(const char* str 0)

for every class there can be only one default constructor.

COPY CONSTRUCTOR:
A copy constructor is a special constructor that can be called to copy an object. The copy constructor for class Part has the form
Part::Part(const Part&).

DESTRUCTOR:
Whenever an object goes out of scope it is destroyed and the memory used by that particular object will be reclaimed.
Part::~Part().


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape