Answers for "what are constructors and destructors c++"

C++
1

what are constructors and destructors c++

class A
{
    // constructor
    A()
    {
        cout << "Constructor called";
    }

    // destructor
    ~A()
    {
        cout << "Destructor called";
    }
};

int main()
{
    A obj1;   // Constructor Called
    int x = 1
    if(x)
    {
        A obj2;  // Constructor Called
    }   // Destructor Called for obj2
} //  Destructor called for obj1
Posted by: Guest on June-06-2021

Code answers related to "what are constructors and destructors c++"

Browse Popular Code Answers by Language