Golang passing arrays to the function and modifying it

后端 未结 2 777
遇见更好的自我
遇见更好的自我 2021-01-21 14:47

In most languages (like c++) passing arrays result in implicitly passing it by a reference, so any changes to the passed array in the function will result in changing the origin

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-21 15:45

    What you are defining is not array but a slice of an array which is passed by reference as specified in golang documentation. Check this link.

提交回复
热议问题