Question 12
Back to Exercise
What is the output of the following C++ program?
#include <iostream>
struct Cell {
static inline int made = 0;
int id;
Cell() : id(++made) { std::cout << id; }
~Cell() { std::cout << '~' << id; }
};
int main() {
{
Cell grid[3];
std::cout << '|';
}
std::cout << '\n';
return 0;
}
- A 123|~3~2~1 Correct
- B 123|~1~2~3
- C |123~3~2~1
- D 111|~1~1~1
Correct Answer: Option A
Array elements are constructed from first to last and destroyed in reverse order.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!