What is x after “x = x++”?

后端 未结 17 1382
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 06:26

What happens (behind the curtains) when this is executed?

int x = 7;
x = x++;

That is, when a variable is post incremented and assigned to

17条回答
  •  忘掉有多难
    2020-11-21 06:51

    ++x is pre-increment -> x is incremented before being used
    x++ is post-increment -> x is incremented after being used

    int x = 7; -> x get 7 value 
    x = x++; -> x get x value AND only then x is incremented

提交回复
热议问题