Incrementor logic

后端 未结 7 2123
醉梦人生
醉梦人生 2020-11-27 05:37

I\'m trying to get deeper with post and pre incrementors but am a bit stuck with the following expression :

public static void main(String[] args) {
    int i         


        
相关标签:
7条回答
  • 2020-11-27 06:11

    I traced the value of i and here are the results:

    i = i+=(++i + (i+=2 + --i) - ++i);
    initialization: i = 0;
    ++i: i = 1;(1st one) and store this value
    (i+=2 + --i): In it
     --i: i = 0;(i was changed by the previous ++i)
     i += 2 + 0: i = 2;(value of the inner (i+=2 + --i), store it)
    ++i: i = 3;
    1 + 2 -3: i = 0;
    i += 0: i = 0;
    

    The value of the 2nd i from the left is not zero, it is the value of i after all the operations to the right are finished.

    0 讨论(0)
提交回复
热议问题