What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A{
public:
A(){
cout<<“Constructor called\n”;
}
~A(){
cout<<“Destructor called\n”;
}
};
int main(int argc, char const *argv[])
{
A *a = new A[5];
delete[] a;
return 0;
}
a) “Constructor called” five times and then “Destructor called” five times
b) “Constructor called” five times and then “Destructor called” once
c) Error
d) Segmentation fault
Answer: a
Explanation: In this, we have first initiated five-pointer variables using new keyword hence fives time constructor will be called after that as we using delete[](used for deleting multiple objects) to delete variables hence all the five objects created will be destroyed and hence five times destructor will be called.
Related Posts
What are the portability concerns founded in Seeheim model?
Which of the following is the main task accomplished by the user?
Which among the following are the functions that any system with a user interface must provide?
The _____________ system is widely used for mapping from Java objects to relations.
The ______________ layer, which provides the interface between the business-logic layer and the underlying database.
The _____________ layer, which provides a high-level view of data and actions on data.
Which layer deals which deals with user interaction is called _____________ layer.
Join The Discussion