Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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
Source by www.studytonight.com #
 
PREVIOUS NEXT
Tagged: #constructors #destructors
ADD COMMENT
Topic
Name
8+5 =