Constructor is used to initialize variables, set default values, allocate memory if needed and such. It is called when you assign class to variable eg, List list = new List(); Destructor is mostly used to free used memory. It is called when you want to delete used variable. Eg, delete list;
You use constructors and destructors in a class or object. When you instantiate an object, you sometimes would want to create an initialize variables, allocate memory, etc. in it, you use a constructor for that purpose. A destructor function runs automatically as soon as the object gets destroyed - usually, you need this function to manually free used memory. For more information about it, google it.
Let's say you have a game programmed in C++ and you have a class that defines a player... he has hit points, weapons, abilities and such. When you create an instance of this player, it would be nice if he started with full hit points, and maybe even triggers an event to tell everyone he's spawned into the game. You could do all this within a constructor. At the same time, when that player leaves or dies - would you really want the memory to still be in use to hold his hitpoints, abilities and weapons? no, you would want it to be used for other players. Destructors will execute code at the end of an objects life - and free up memory that is no longer required. Hmm... funny how people just google the question then post what they find.
The use of constructors is to initialize objects.Constructor is special member function which has same name as class name and used to construct the object of the class. The function of initialization is automatically carried out by the use of a special member function called a constructor. Constructor get called automatically when object is created Syntax for constructor <class name> { arguments}; Destructors are also special member functions used in C++ programming language. Destructors have the opposite function of a constructor. The main use of destructors is to release dynamic allocated memory. Destructors are used to free memory, release resources and to perform other clean up. Destructors are automatically named when an object is destroyed. Like constructors, destructors also take the same name as that of the class name. General Syntax of Destructors ~ classname();
Constructor is used to initialize the objects . It will initialize the private , protected and public data members with the values mentioned in the constructor. Destructor simply deallocate the memory allocated by the constructors .