Sunday, 25 April 2021

Dynamic Object and Destructor calling for Dynamic Object Qus - 1

 #include<iostream.h>

#include<conio.h>

class A

{

 public:


 A()

 {

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

 }

 void show()

 {

 cout<<"Show"<<endl;

 }

~A()

{

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

}

};

int main()

{

clrscr();

{

A ob;

ob.show();

A ob1=A();

ob1.show();

A *p=new A();        //Dynamic object

p->show();

delete p;         //desc. for p

}

getch();

return 0;


}

No comments:

Post a Comment