Sunday, 25 April 2021

Dynamic object and Destructor calling in C++ Qus - 2

 class A

{

    public:

    A()

    {

        cout<<"C-A"<<endl;

    }

      ~A()

    {

        cout<<"D-A"<<endl;

    }

};

int main() {

  A *p=new A[3];

  delete  p;

}


delete p;

output

C-A

C-A

C-A

D-A


delete [] p;

output

C-A

C-A

C-A

D-A

D-A

D-A





No comments:

Post a Comment