Wednesday, 7 October 2015

Write a CPP Program To Perform Contructor And Destructor

Write a CPP Program To Perform Contructor And Destructor
1:  #include<iostream.h>  
2:  #include<stdio.h>  
3:  class sum  
4:  {  
5:    int a,b;  
6:  public:  
7:    sum()  
8:    {  
9:      cout<< "Enter 2 numbers" << endl;  
10:      cin>>a>>b;  
11:      cout<< "Sum = "<<a+b;  
12:    }  
13:    ~sum()  
14:    {  
15:      cout<< "\nDestructor invoked"<<endl;  
16:    }  
17:  };  
18:  int main()  
19:  {  
20:    sum t;  
21:  }  

No comments:

Post a Comment