Java: pre-,postfix operator precedences

前端 未结 5 668
-上瘾入骨i
-上瘾入骨i 2020-12-03 14:41

I have two similar questions about operator precedences in Java.

First one:

int X = 10;
System.out.println(X++ * ++X * X++); //it pr         


        
5条回答
  •  误落风尘
    2020-12-03 15:07

    For the second one ->

    int a=1, b=2;             
    a += b + a++;
    

    Compiler will convert it to

     a = a + b + a++;
    

    Then apply your logic and you will find the reason why a is 4.

提交回复
热议问题