what does x— or x++ do here?

后端 未结 7 1166
猫巷女王i
猫巷女王i 2021-01-23 01:53

it is a silly Q for most of u - i know - but i one of the beginner here, and I can not understand why the output in here are 12 what does this (x--) do to the resu

7条回答
  •  伪装坚强ぢ
    2021-01-23 02:50

    x++ is essentially x = x + 1 (the same applies for ++x). x is incremented by 1.

    x-- is essentially x = x - 1 (the same applies for --x). x is decremented by 1.

    The difference is that how x++ and ++x is used in the statement/expression: In ++x, x is incremented by 1 first before being used while in x++, x is used (before incrementation) first and once it's used, it gets incremented by 1.

提交回复
热议问题