The equality operator evaluates left to right and yields 1
if the
specified equality is true and 0
if it is false.
Thus the expression in the if statement
if (a==b==c)
is equivalent to
if ( ( a == b ) == c )
As a
is equal to b
(the both are equal to 0
) then the first sub-expression ( a == b )
evaluates to 1 and you actually have
if ( 1 == c )
As c is equal to 0 then the expression 1 == c
evaluates to 0 and the compound statement of the if statement is bypassed. As a result the sub-statement of the else statement is executed
printf("222\n");
Maybe the author of the code meant the following if statement
if ( ( a == b ) && ( b == c ) )
In this case as a
is equal to b
and b
is equal to c
then this condition evaluates to logical true.
On the other hand, as a
is equal to b
then this if statement is also executed.
if (a==b)
{
printf("333");
}