Write a program to show the default constructor and destructor call.
#include<iostream> using namespace std; class A { private: int x; public: A() { cout << "constructor" << endl; } void print(int a) { x = a; cout << "x = " << x << endl; } ~A() { cout << "destructor" << endl; } }; int main() { A obj; obj.print(30); return 0; }
Output
constructor x = 30 destructor