++x and x++

Both are self-increment operations, the difference is:
++x is self-increment first, then
x++ is first operation, then self-increment (in this example, x first participates in the assignment operation with a value of 2, and then Perform self-increment operation.)
Example:

  • ++x
// 先自增
x = 2
y = ++x
输出:y = 3; x = 3
  • x++
// 先运算
x = 2
y = x++
输出:y = 2; x = 3

Same as subtraction

Guess you like

Origin blog.csdn.net/zibery/article/details/123062365