Don’t Trust Operator Precedence

Consider the following code:

int main(void)
{
 int x=10,y=20,res;

 res=x---y;

 printf("res=%d x=%d y=%d\n",res,x,y);


 return 0;
}

the statement x—y can be parsed as:

(x--) - y

or

x - (--y)

The first one is the correct so It will print

res=-10 x=9 y=20

 

Conclusion

Don’t trust operator precedence , it creates hard to read code , always use parentheses