Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A
{
~A(){
cout<<“Destructor called\n”;
}
};
int main()
{
A *a1 = new A();
A *a2 = new A();
return 0;
}

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A
{
~A(){
cout<<“Destructor called\n”;
}
};
int main()
{
A *a1 = new A();
A *a2 = new A();
return 0;
}
a) Destructor called
b) Destructor called
Destructor called
c) Error
d) Nothing is printed

Answer: d
Explanation: The pointer object is created is not deleted hence the destructor for these objects is not called hence nothing is printed on the screen.

Join The Discussion