Advertisements
Advertisements
प्रश्न
Explain the Destructor with an example.
स्पष्ट कीजिए
Advertisements
उत्तर
A destructor is a special member function that is automatically called when an object is destroyed or goes out of scope. Its primary role is to deallocate memory and release resources (like closing files) that were acquired by the object during its lifetime.
Example:
class Sample {
public:
// Constructor
Sample() {
cout << "Object created";
}
// Destructor
~Sample() {
cout << "Object destroyed";
}
};shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2023-2024 (July) Official Board Paper
