Coupon Accepted Successfully!



  1. C++ provides a pair of in-built functions called constructor and destructor. The compiler automatically executes these functions. When an object is created, constructor is executed. The programmer can also pass values to the constructor to initialize member variables with different values. The destructor destroys the object. It is executed at the end of program when objects are of no use.
  2. Constructors and destructors decide how the objects of a class are created, initialized, copied, and destroyed. They are member functions. Their names are distinguished from all other member functions because they have the same name as the class they belong to.
  3. It is also possible to create constructor with arguments as in normal functions.
  4. Similar to functions, it is also possible to overload constructors and assign default arguments.
  5. When we pass an object by value into a function, a temporary copy of that object is created. All copy constructors require one argument, with reference to an object of that class. Using copy constructors, it is possible for the programmers to declare and initialize one object using reference of another object. Thus, whenever a constructor is called, a copy of an object is created.
  6. We can also make the object constant by the keyword const. Any effort to alter values of variables made by it will generate an error. The constant object can access only constant functions.
  7. The compiler automatically calls the constructor and destructor. We can also call the constructor and destructor in the same fashion as we call the normal user-defined function. The calling methods are different for constructor and destructor.
  8. Objects are created with names. It is possible to declare objects without name. Such objects are known as anonymous objects.
  9. When the constructor and destructor are private, they cannot be executed implicitly, and hence, it is a must to execute them explicitly.
  10. We can also call the constructor and destructor in the same fashion as we call the normal user defined function.
  11. The class declaration can also be done inside the other class. While declaring object of such class, it is necessary to precede the name of the outer class. The name of outer class is called qualifier name, and the class defined inside is called as nested class.
  12. The dynamic construction means allocation of memory by constructor for objects and dynamic destruction means releasing memory using the destructor.
  13. To use main() as a constructor and destructor, we need to define class with the name main.
  14. Similar to normal and member functions, constructors also support recursion.
  15. For global object, constructor is executed before main() function and destructor is executed after the completion of execution main() function.

Test Your Skills Now!
Take a Quiz now
Reviewer Name