C++ program to demonstrate the use of constructors and destructors
kw.cpp
#include<iostream>usingnamespacestd;classkw{public:kw(){cout<<"\nConstructor is called";}~kw(){cout<<"\nDestructor is called";}};intmain(){kwk;kw();k.~kw();}
Output
kodingwindow@kw:~$ g++ kw.cpp kodingwindow@kw:~$ ./a.out
Constructor is called
Constructor is called
Destructor is called
Destructor is called
Destructor is called
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.