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.

Get hands-on with 1200+ tech skills courses.