tampurus

8 Destructor

Dec 2nd, 2021 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class student{
  4.     int x;
  5.     public:
  6.     student(){
  7.         x = 67;
  8.         cout<<"constructor called x is ";
  9.     }
  10.     void display(){
  11.         cout<<x<<endl;
  12.     }
  13.     ~student(){
  14.         cout<<"Destructor called";
  15.     }
  16.  
  17. };
  18. int main()
  19. {
  20.     student s;
  21.     s.display();
  22.     return 0;
  23. }
  24. /*
  25. Output
  26. constructor called x is 67
  27. Destructor called
  28. */
Advertisement
Add Comment
Please, Sign In to add comment