Differentiate between a constructor and a destructor in C++.

devquora
devquora

Posted On: Feb 22, 2018

 

ConstructorDestructor
A constructor is used to initialize the instance of a class or object.A destructor simply destroys the objects when they are no longer needed.
A constructor is called when a new instance of a class or object is created.A destructor is called when an instance of a class or object is deleted or released.
A constructor allocates the memory.A destructor releases or frees the memory.
Constructors can have arguments.A destructor cannot have any arguments.
Overloading of the constructor is possible in C++.Overloading of destructors is not possible.
A constructor has the same name as class name.A destructor also has the same name as class name but with (~) tiled operator.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    C++ Interview Questions

    Explain what is OOP?

    Object-oriented programming (OOP) is a type of computer programming, also more commonly known as software design, in wh..

    C++ Interview Questions

    What is the difference between #import and #include in C++?

    The statement #include is used in C++ to include the source file or import the header files containing definitions of f..

    C++ Interview Questions

    What is ‘this’ pointer?

    The ‘this’ pointer is passed as a hidden argument to all the non-static member method calls and is available as a l..