[Solved] operator precedence in c for “==” and “||” [closed]


Because of operator precedence the condition

int i = 10;
if (i == 20 || 30)

is equivalent to

if ((i == 20) || 30)

so the first test if false, the second, being non-0, evaluates to true. Since one of the two evaluations is true, the whole test is true.

What happens when you replace || with &&?

if ((i == 20) && 30)

here since one of the two evaluations is false, the whole test is false.

solved operator precedence in c for “==” and “||” [closed]