Passing address, but it is working like call by value in C?

后端 未结 4 1787
南笙
南笙 2020-12-04 00:40

Hello I am a beginner in C programming language. Recently I read about call by value and call by address. I have learned that in call by address changes in the called functi

4条回答
  •  醉酒成梦
    2020-12-04 01:21

    You are simply setting the value of the pointer in the function, not the value of the pointed to variable. The function should use the following code:

    *ptr = y;

    This derefences the pointer (exposing the value pointed to), and therefore when you use the equals operator, the memory pointed at is modified, not the pointer itself. I hope this helps to clarify things.

提交回复
热议问题