Ask Question
30 August, 06:18

Given the class definition: class CreateDestroy { public: CreateDestroy () { cout << "constructor called, "; } ~CreateDestroy () { cout << "destructor called, "; } }; What will the following program output? int main () { for (int i = 1; i < = 2; + +i) CreateDestroy cd; return 0; }

A. constructor called, destructor called, constructor called, destructor called,

B. constructor called, constructor called,

C. constructor called, constructor called, destructor called, destructor called,

D. Nothing

+3
Answers (1)
  1. 30 August, 08:50
    0
    (A) constructor called, destructor called, constructor called, destructor called.

    Explanation:

    In the class definition we have created a constructor which prints constructor called and a destructor which prints destructor called. Since the class contains default constructors and destructors but when we define constructor and destructor in the class defaults are removed from the class. In the code the loop is running 2 times creating a object so constructor is called when that iteration finishes it deletes that object so destructor is called and it is happening 2 times.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Given the class definition: class CreateDestroy { public: CreateDestroy () { cout ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers