Junior
How are parameters passed to a function in Go: by pointer or by value?
sobes.tech AI
Answer from AI
By value. This means that when a function is called, a copy of the value of the passed argument is created.
Exceptions are:
- Slices
- Maps
- Channels
- Pointers
In these cases, a copy of the header (header) of the data structure (slices, maps, channels) or the pointer itself (for pointers) is passed. Modifying data through this header or pointer inside the function will be visible outside.