Pointers
Explore pointers in Go to understand how they reference memory addresses and enable passing variables by reference. Learn why Go supports pointers without pointer arithmetic, how to use pointers with structures, and how this facilitates advanced data structures and efficient function parameter handling.
Pointers in Go
Go has support for pointers but not for pointer arithmetic, which is the cause of many bugs and errors in programming languages like C. A pointer is the memory address of a variable. We need to dereference a pointer in order to get its value— dereferencing is performed using the * character in front of the pointer variable. Additionally, we can get the memory address of a normal variable using an & in front of it.
Pointers vs. variables: A graphical explanation
The following diagram shows the difference between a pointer to an int and an int variable.