Program To Illustrate The Types of Constructors along With A Destructor:
#include<iostream>
using namespace std;
class A
{
int x;
public:
A()
{x=0;
}
A(int y)
{
x=y;
}
A(A &c)
{
x=c.x;
}
~A()
{
cout<<"\nDestructor Called";
}
void display()
{
cout<<"\nValue is "<<x;
}
};
main()
{
A p,q(10),r(p),s(q);
p.display();
q.display();
r.display();
s.display();
{A t(12);
cout<<"\nEntered In Inside Block";
t.display();
}
cout<<"\nEntered In Main Block\n";
}
I want to thank Mr.Piyush Arora for this idea
#include<iostream>
using namespace std;
class A
{
int x;
public:
A()
{x=0;
}
A(int y)
{
x=y;
}
A(A &c)
{
x=c.x;
}
~A()
{
cout<<"\nDestructor Called";
}
void display()
{
cout<<"\nValue is "<<x;
}
};
main()
{
A p,q(10),r(p),s(q);
p.display();
q.display();
s.display();
{A t(12);
cout<<"\nEntered In Inside Block";
t.display();
}
cout<<"\nEntered In Main Block\n";
}
I want to thank Mr.Piyush Arora for this idea