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

后端 未结 5 1514
被撕碎了的回忆
被撕碎了的回忆 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:53

    When you do * ptr++, you are actually doing * (ptr++), so the pointer get incremented, not the variable it points to

    When ++ *ptr, it's actually ++(* ptr), so it increments the value returned by the pointer

提交回复
热议问题