C++ program to demonstrate the use of constructors and destructors
kw.cpp
#include <iostream>
using namespace std;
class kw
{
public:
    kw()
    {
        cout<<"\nConstructor is called";
    }
    ~kw()
    {
        cout<<"\nDestructor is called";
    }
};
int main()
{
    kw k;
    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:~$
Advertisement