Incrementing pointer (ptr++) and (*ptr++)

后端 未结 5 1492
被撕碎了的回忆
被撕碎了的回忆 2021-01-07 14:33

I was revisiting pointers when I had this doubt.

int *ptr;
int arr[5] = {10,20,30,40,50};
ptr = &arr[0];

Now printf(\"Value: %d\"

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-07 14:48

    The order of C Precedence from high priority:

    ()
    ++
    * & for pointers
    * /
    + -

    so,

     *ptr++ equivlant to *(ptr++)
     ++*ptr equivlant to ++(*ptr)
    

    and for this line *ptr++; it will only increment the ptr pointer.

提交回复
热议问题