Write a program to show the parameterized constructor and destructor call.
#include<iostream> using namespace std; class A { private: int x,y; public: A() { cout << "Default constructor" << endl; } A(int a,int b):x(a),y(b) { cout << "Parameterized constructor" << endl; } void print() { cout << "x = " << x << " y = " << y << endl; } ~A() { cout << "destructor" << endl; } }; int main() { A obj(34,57),obj2; obj.print(); obj2.print(); return 0; }
Output
Parameterized constructor Default constructor x = 34 y = 57 x = 1998107341 y = 1955189716 destructor destructor