LearnFrenzy
Sign in Take a free test

STL Algorithms and Iterators · STL Algorithms MCQ · Question 8

binary_search on unsorted data Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

What happens if you call std::binary_search on an unsorted vector?

  • A It sorts the vector first
  • B The result is unreliable – the precondition (sorted range) is violated Correct
  • C Compile error
  • D It throws
Correct Answer: Option B

The library does not check; you get wrong answers silently.

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