While studying C, I came across a peculiar problem that also persists in C++. The problem is mainly about using several relational operators within an expression without any logical operators.
Such usage was bugged and the expressions kept returning arbitrary results.Although bugged, I still wonder how the runtime handles such situations.
An example expression is such as: if(a < b < c)
Expression-result couplings are such as following. The results are the values displayed when the expression is put into printf() or cout:
You may assume all of the expressions to be in cout as: cout << (a < b < c);
I just wanted to add, that the confusion is probably because the programming language looks a bit like some mathematics as the same symbols are used. But it has a different meaning.
For example, the = sign. In mathematics, we could write
x = x/2 + 3
That's an equation, we can solve it and get the result, x = 6.
But in C OR C++, the = sign means assignment of a value, x = x/2 +3 ;
after execution, the value of x will depend on its previous value, and will change every time it is executed
OK, so I got off topic here. But my point is, don't mix up the meaning of symbols in mathematics with their meaning when programming.