juniorGolang

What is a pointer in Go and why use it?

Updated Apr 28, 2026

Short answer

A pointer holds the memory address of a value. It allows passing references to data instead of copying the data itself.

Deep explanation

Go is strictly 'pass by value'. When passing large structs to functions, copying the entire struct is inefficient. Pointers (*T) allow functions to mutate the original data and save memory allocation overhead. The & operator gets the address of a variable, and * dereferences it.

Real-world example

Passing a large database configuration struct to various connection builders without duplicating memory.

Common mistakes

  • Returning pointers to local variables that might escape to the heap, which isn't necessarily an error in Go (due to escape analysis), but can impact GC performance.

Follow-up questions

  • Does Go have pointer arithmetic like C/C++?

More Golang interview questions

View all →