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
  • 60,763
  • 5
  • 37
  • 77

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
  • 988
  • 5
  • 11
  • 21