Why does call-by-value example not modify input parameter?

前端 未结 6 565
栀梦
栀梦 2020-11-28 16:51

In the following call-by-value example, I cannot understand why this code is not changing the value of the 5 to a 6.

Line 11 calls the function changeValue which ha

6条回答
  •  失恋的感觉
    2020-11-28 17:21

    AND:

    the copy is assigned 6, but the change is not returned.

    you need some reference or pointer if you want to change the value:

    try using a method signature like:

    void changeValue(int& value)
    

    that will probably do what you expected

提交回复
热议问题