Updating pointers in a function

前端 未结 5 1452
鱼传尺愫
鱼传尺愫 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:44

    C is passing parameters by value, so it makes a copy of pSrc inside your function, and all the changes you've made are applied to a copy of pSrc. If you want to change the value of pSrc, then you should pass a pointer to pSrc, like this:

    static void func(char **pSrc){ // pointer to char*
         int x;
         for (x = 0; x < 10; x++)
             (*pSrc)++
    }
    

提交回复
热议问题