ProgrammingModerateProduct-company placement · C++

What is printed?

What is printed?
int main() {
    set<int, greater<int>> s{3, 1, 3, 2};
    for (int x : s) cout << x;
    cout << s.size();
}
  1. A. 3213
  2. B. 31323
  3. C. 1233
  4. D. 3214

Correct answer: A. 3213

A set keeps unique keys ordered by its comparator; greater<int> gives descending order and the duplicate 3 is discarded.

More OOP with C++ and Java questions

Exams that ask this topic