Why is this Java operator precedence being ignored here?

前端 未结 7 1462
栀梦
栀梦 2020-12-10 18:13

The following code prints out \"3\", not \"4\" as you might expect.

public class Foo2 {
    public static void main(String[] args) {
        int a=1, b=2;            


        
7条回答
  •  不知归路
    2020-12-10 19:02

    The postincrement/decrement operator (a++) returns the value before the increment. The preincrement/decrement (++a) returns the value after the increment.

提交回复
热议问题