What is the difference between prefix and postfix operators?

前端 未结 13 1806
天命终不由人
天命终不由人 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:35

    fun(10) returns 10. If you want it to return 11 then you need to use ++i as opposed to i++.

    int fun(int i)
    {
        return ++i;
    }
    

提交回复
热议问题