Anonymous School
(Minds of Hacker)
--------------------------------
Write a program that demonstrates destructors in C++.
#include<iostream>using namespace std;class x{public:int num1,num2;~x(){cout<<"Destructor is called\n";}};int main(){cout<<"starting of int\n\n";x num1,num2;cout<<"Enter the two numbers\n";cin>>num1.num1>>num2.num2;{cout<<"starting of brases\n\n";x a,b,c;a.num1=1;a.num2=2;b.num1=4;c.num2=5;cout<<"\n\nEnding of braces\n";}cout<<"\n\nEnding of int\n";return 0;}
Output:
Enter the two numbers
2
3
starting of brases
Ending of braces
Destructor is called
Destructor is called
Destructor is called
Ending of int
Destructor is called
Destructor is called
*******************Don't Make Learning Hard*****************
Follow us on :-
1) YouTube Channel :- Click Here
2) Blog :- Click Here