Math-like chaining of the comparison operator – as in, “if ( (5

C does not understand math-like syntax, so

if(1<j<=5)

is not interpreted as you expect and want; it should be

if (1 < j && j <= 5)

or similar.

As explained in other answers, the expression is evaluated as

 ((1 < j) <= 5)

 =>  ("true" <= 5)

 =>  "true"

where “true” (boolean value) is implicitly converted to 1, as explaneid e.g. here, with references to standards too, and this explain why “true” has to be “less than” 5 (though in C might not be totally correct to speak about “implicit conversion from bool to int”)

Leave a Comment