6

The following code std::cout << (0 < 5 < 2); outputs 1 (true) to the console, even though mathematically speaking, 5 < 2 is false. What is the logic behind this?

Hypothesis: This is because 0 < 5 is calculated as 1, therefore 0 < 5 < 2 is calculated as 1 < 2. Am I correct?

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108

1 Answers1

0

You have answered the question yourself, you are 100% correct. Evaluation is done on the basis of precedence. Might help you:-C++ operators Precedence

Abhishek Dutt
  • 1,308
  • 7
  • 14
  • 24