Is there a difference between x++ and ++x in java?

后端 未结 16 2423
-上瘾入骨i
-上瘾入骨i 2020-11-22 02:34

Is there a difference between ++x and x++ in java?

16条回答
  •  感情败类
    2020-11-22 03:34

    yes

    ++x increments the value of x and then returns x
    x++ returns the value of x and then increments

    example:

    x=0;
    a=++x;
    b=x++;
    

    after the code is run both a and b will be 1 but x will be 2.

提交回复
热议问题