LearnFrenzy
Sign in Take a free test

Arrays and Vectors · Predict the Output · Question 12

Comparing std::array objects Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

What is the output of the following C++ program on a 64-bit system?

main.cpp
#include <array>
#include <iostream>

int main() {
    std::array<int, 3> a{1, 2, 3}, b{1, 3, 0}, c = a;
    c[2] = 4;
    std::cout << (a == b) << (a < b) << (c > a) << (a != c) << '\n';
    return 0;
}
  • A 0111 Correct
  • B 0011
  • C 1011
  • D 0110
Correct Answer: Option A

Comparisons are lexicographic: a and b first differ at index 1 (2 < 3), so a < b. c is a copy with the last element changed to 4, so c > a and a != c.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links