Updating pointers in a function

前端 未结 5 1442
鱼传尺愫
鱼传尺愫 2020-12-11 03:52

I am passing a pointer a function that updates it. However when the function returns the pointer it returns to the value it had prior to the function call.

Here is m

5条回答
  •  独厮守ぢ
    2020-12-11 04:50

    When you give a pointer to a function, you have a copy of the reference value that you originally had.

    Then, if you modify your pointer, you're modifying a copy.

    If you want to update the original one, you need to pass it with a double pointer ** which will let you modify the original pointer, passing a "reference to a reference" (double pointer).

提交回复
热议问题