MENU
Question -

Differentiate between Constructor and Destructor functions giving suitable example using a class in C++. When does each of them execute ?



Answer -

Constructor is a member function which creates an object.
Destructor is a member function which deallocates the memory occupied by an object

class ABC
{
int a, b; 
public 
ABC () //Constructor
{a=0;b=0;}
~ ABC () //Destructor
{
}
};

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×