Pre- and postincrement in Java

后端 未结 6 1763
不思量自难忘°
不思量自难忘° 2021-01-17 13:48

I just wanted to create a little Java-Puzzle, but I puzzled myself. One part of the puzzle is:

What does the following piece of code do:



        
6条回答
  •  情书的邮戳
    2021-01-17 14:28

    i += ++i + i++ + ++i; is the same as i = i + ++i + i++ + ++i;

    The right-hand side is calculated from left-to-right, yielding i = 1 + 2 + 2 + 4; (which yields i = 9).

提交回复
热议问题