Is Go pass-by-value or pass-by-reference, and how does this apply to slices, maps, and pointers?

Last updated 20 June 2026

Go is always pass-by-value: every argument is copied into the function. The confusion arises because some types are small descriptors that contain pointers, so copying the descriptor still lets you reach the same underlying data.

  • Everything is copied: A function receives a copy of the value; reassigning the parameter never affects the caller.

  • Slices: A slice is a header (pointer, len, cap) that is copied; the copy points to the same backing array, so mutating elements is visible to the caller, but append that reallocates is not.

  • Maps: A map value is a reference to the same internal hash table, so writes through the copy are seen by the caller.

  • Pointers: The pointer itself is copied, but it still addresses the same memory, so dereferencing and mutating affects the original.

  • Rule of thumb: To modify a struct or basic value in the caller, pass a pointer (*T); slices, maps, and channels already share underlying state.

  • https://dave.cheney.net/2017/04
All Golang interview questions