C - pointer behavior with pre and post increment

前端 未结 6 1335
日久生厌
日久生厌 2021-01-22 08:50

In am doing some experiment in C pointers and trying to understand its behaviour. The following are my assumptions for the below codes. Correct me if I am wrong. I have the foll

6条回答
  •  感情败类
    2021-01-22 09:19

    Both ptr++ and *ptr++ increment the pointer after they have returned, in the first case, the previous address to which ptr was pointing, and in the second case, the value from this address. You do not do anything with the results, so you do not see the difference.

    *++ptr will first increment ptr, then returns the value to which it now points.

    ++*ptr will get the value to which ptr points, increment it, and then return.

提交回复
热议问题