What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: A(){ cout<<"Constructor called "; } ~A(){ cout<<"Destructor called "; } }; int main(int argc, char const *argv[]) { A *a = new A[5]; delete a; return 0; }

Question:
What will be the output of the following C++ code?

#include <iostream>
using namespace std;
class A{
public:
 A(){
  cout<<"Constructor called
";
    }
 ~A(){
  cout<<"Destructor called
";
     }
};
int main(int argc, char const *argv[])
{
 A *a = new A[5];
 delete a;
 return 0;
}

1.Constructor called five times and then Destructor called five times

2.Constructor called five times and then Destructor called once

3.Error

4. Segmentation fault

Posted Date:-2021-01-31 14:08:04


More MCQS Questions and answers

Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!