 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you how you can implement constructors and destructors together in a class in C++. Before starting, you can note my information. You can connect with me by following these details. You can download my app TakMS that is available on Google Play. Now coming on to the topic, you can see a code which is written in front of you. Here I have included a header file IO screen. Then I have used a namespace that is STD. It is a predefined namespace. Then name of class is complex. Its attributes real and imaginary are declared here in form of RNI variables. Both are of integer type. Then in public section, first I have implemented default constructor. So constructor is used to initialize attributes of an object. It is called automatically whenever object of a class is created. So this constructor will initialize real and imaginary with 10 and 20 respectively. Now second block of this definition is destructor. So destructor is called when an object goes out of scope. So you can see that in main function I have created an object C1. So at the time of its creation, default constructor will be executed automatically. And after completion of this main function, when control will be out from this main function, then automatically this destructor will be executed and it will display destructor called message on console. So this message will say that destructor is actually executed because I have not written any particular statement for calling of the destructor. So it is called automatically without writing any particular statement. So constructor will call whenever you will be creating any object, but destructor will be called automatically when an object goes out of scope or you can say a function has terminated. And the proof destructor called message is the proof that this destructor is executed. Then print function, which is printing real and imaginary values on console. Now I am executing this code. You can see the output 10 and 20 are displayed because of constructor calling. And at the end destructor called message is printed. Now I am going to create one more object C2 and I am printing its values by calling print function. This time I have created total two objects. So two objects will be destroyed with the help of destructor and their memory will be released by the destructor so that that memory can be used by some other programs. So this time destructor called message will be displayed twice. So let's see the output. You can see 10, 20, 10, 20 are displayed two times because two objects are created. So two times constructor is working. You can also see destructor called message are printing twice. So destructor also executed twice. So if you have created more than one objects like n number of objects, so constructor will be called n number of times. Similarly, destructor will be called n number of times. And remember that for destructor you have to use this tilde sign. It differentiate constructor and destructor because name of constructor and destructor are same as their classes. So I hope you have understood the use of constructor which is for object initialization and the use of destructor which deallocates the memory and prints a particular message on console. And it is called automatically when object goes out of scope. So implement this concept. If you want to watch more programming related videos, you can subscribe my YouTube channel. Thank you for watching this video.