• Tutorials
  • Courses
  • Tracks

C++ | Destructors | Question 10

Last Updated :
Discuss
Comments

What will be the output?

C++
#include <iostream>
class Sample {
public:
    ~Sample() {
        std::cout << "Destructor executed\n";
    }
};

void createObject() {
    Sample s;
}

int main() {
    createObject();
    std::cout << "Main done\n";
}


Main done

Destructor executed

Destructor executed
Main done

Main done
Destructor executed

Share your thoughts in the comments