
Mastering Pointers in Go – A Complete Guide | by Thomas Langhorst | January 2025

In this article, I’ll show you what pointers are, how to use them in Go, and I’ll also give you some common best practices for using them effectively.
So, without further ado, let’s get started!
Generally speaking, pointers are used to store the memory address of another variable. In other words, pointers point to a specific memory location where a value is stored – hence the name.
Memory addresses are stored in hexadecimal format. Therefore, pointer values are also in hexadecimal format. An example would be the value 0xc00001c088
.
I think a real-world analogy might make things clearer: imagine your variable as a house. A pointer to this variable is like the address of the house, not the house itself.
In Go, memory is freed (released) by the garbage collector. However, there are cases where you need to explicitly allocate memory. Memory is dynamically allocated, meaning your data structures can grow and shrink in size as needed. We saw this in my article on arrays and slices.
Dynamic allocation of memory space in Go can be done in two ways: make()
function (which we have already talked about in the…