When do function arguments pass by value in Go?
In all of the C languages, arguments to a function are always passed by value meaning that the function always gets a copy of the argument, just like there’s an assignment statement that assigns values to the meaning of the argument.
Pointer passing is also assigning a copy of a pointer, not the data to which it points. So that’s why you can change the value of the data in the function with a pointer. Because a pointer is an address that points to the data, the copy is still at that address.
Two special data structures are Map and Slice. They behave much like Pointers in that they contain a pointer to the underlying data, allowing you to view Slice in depth. So Map and Slice arguments do not copy the data they point to, and the data can be changed directly in the function.
If the function takes an interface, an interface containing the struct will copy the entire struct, and if it contains a pointer, it will not copy the data to which the pointer points.
Reference: When are function parameters passed by value?
For more content, follow me on Github.