Why does this if-statement combining assignment and an equality check return true?

后端 未结 4 687
醉梦人生
醉梦人生 2020-12-22 23:25

I\'ve been thinking of some beginner mistakes and I ended up with the one on the if statement. I expanded a bit the code to this:

int i = 0;
if          


        
4条回答
  •  情歌与酒
    2020-12-22 23:40

    It has to do with parsing an the right to left rules. Eg y = x+5.
    All sub-expressions are weighted in importance. Two expressions of equal importance are evaluated right to left, . The && expression side is done first, followed by the LHS.

    Makes sense to me.

提交回复
热议问题