CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C++ DETAILS
Question :
In C++, what is a constructor,destructor?
Category C++ Interview Questions
Rating (4.4) By 32 users
Added on 10/13/2005
Views 3429
Rate it!
Answers:

In C++

Constructor:This is a member of class which involkes when the object is created.Purpose of constructor is to intialise the objects with required values.

Destructor: It is a member of class which involkes when the object is out of scope.The purpose of destructor is to clear the heap memory.

Submitted by divya e (mail2_divya@yahoo.com)



constructor is a special function, with the same name of the class, with no return type, and is automatically invoked when an object of that class is created;
it is used to initialize the object / object variables;

Destructor has the same name of the class but preceded with a tilda(~) symbol;
it is used to destroy or free the memory allocated for the object; it is automatically called when an object is destroyed;;



 Posted by: shekar    

Contact shekar  Contact shekar

In C++, what is a constructor, destructor?



 Posted by: Saurabh Katiyar    

Contact Saurabh Katiyar  Contact Saurabh Katiyar

Both are members of class only.But the constructor is one which initialized some values with some required values and destructor is one one which clear the heap memory.



 Posted by: vlpyadav    

Contact vlpyadav  Contact vlpyadav

constructor is a special function, with the same name of the class, with no return type, and is automatically invoked when an object of that class is created;
it is used to initialize the object / object variables;

Destructor has the same name of the class but preceded with a tilda(~) symbol;
it is used to destroy or free the memory allocated for the object; it is automatically called when an object is destroyed;;



 Posted by: manzoor    

Contact manzoor  Contact manzoor

Constructor: It used for inislize objects values .It hv same name as class name and Invoked when class is lode.

Destructor: It is also hv same name as class but used to remove address of a objects from heap memory and it is also run autometiclly when Objects is destroy or Class is unload.



 Posted by: Manoj Verma    

Contact Manoj Verma  Contact Manoj Verma

constructor: its a special function with same name as that of class &it doesn't have return type it can be over loaded but their must be difference in no. of parameters even it is automatically called as object of class created.
destructor: this function returns the memory by destroying whatever
constructed by constructor &make it free to use.
regards
ankita



 Posted by: Ankita Mandekar    

Contact Ankita Mandekar  Contact Ankita Mandekar

constructor is a function that has same name as of its class.it is defined with legal initial value
whereas destructor is same as constructor but a prefix ~ is used



 Posted by: vijay anand    

Contact vijay anand  Contact vijay anand

constructor which constructs the members in class destructor means which are members in class



 Posted by: Anand.T.G    

Contact Anand.T.G  Contact Anand.T.G

c++ we want to create user defined data type such as class to behave so closely like built in data type(int,float).
and as we are able to initialize these built in data type at the time of their creation we must be able to do the same with class objects(of type class). so we use constructor to initialize the variables of type class i e objects



 Posted by: azhar    

Contact azhar  Contact azhar

Constructor: is a function with the same name as of its class.it doesn't return any value neither void.
Destructor:it's use to destroy the memory allocated for the object represented by "~"tilda operator. which is automatically called when an object destroyed



 Posted by: jaywant topno    

Contact jaywant  topno  Contact jaywant topno

Contructor is a special member function that allows us to set up values while defining the object,without need to make a seperate call to a member function.

When an object is destroyed a function called Destructor.The most common use of destructors is to deallocate memory that was allocated for the object by the constructor



 Posted by: Sujitha.S    

Contact Sujitha.S  Contact Sujitha.S

a constructor is a public member function which is used for initialising an object of a class when it is created...while a destructor is used to destroy the object when the control comes out of the block...



 Posted by: himanshu jethawa    

Contact himanshu jethawa  Contact himanshu jethawa


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What is a class?
View Answer
What is an object?
View Answer
What is public, protected, private?
View Answer
What is the difference between class and structure?
View Answer
What is friend function?
View Answer
What are virtual functions?
View Answer
What is a scope resolution operator?
View Answer
What do you mean by inheritance?
View Answer
What is polymorphism? Explain with an example?
View Answer
What is the difference between an object and a class?
View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C++ Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/4333/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.66