ProgrammingModerateProduct-company placement · C++

What is printed?

What is printed?
struct T {
    static int n;
    int id;
    T() : id(++n) { cout << id; }
    ~T() { cout << id; }
};
int T::n = 0;
int main() { T a[3]; }
  1. A. 123123
  2. B. 321123
  3. C. 123321
  4. D. 111111

Correct answer: C. 123321

Array elements are constructed in increasing index order and destroyed in the reverse order when the array goes out of scope.

More OOP with C++ and Java questions

Exams that ask this topic