What is the difference between prefix and postfix operators?

前端 未结 13 1572
天命终不由人
天命终不由人 2020-11-22 08:01

The following code prints a value of 9. Why? Here return(i++) will return a value of 11 and due to --i the value should be 10 itself, can anyone ex

13条回答
  •  太阳男子
    2020-11-22 08:49

    The function returns before i is incremented because you are using a post-fix operator (++). At any rate, the increment of i is not global - only to respective function. If you had used a pre-fix operator, it would be 11 and then decremented to 10.

    So you then return i as 10 and decrement it in the printf function, which shows 9 not 10 as you think.

提交回复
热议问题