In C++, a destructor is a special member function that is called automatically when an object goes out of scope or is explicitly deleted. It is used to clean up resources allocated by the object before it is destroyed. The destructor has the same name as the class preceded by a tilde (~).