Pointers
The concept of pointers is simple—a pointer is a language type that represents the memory locations of your values. Pointers in Go are used everywhere, and that's because they give the programmer a lot of power over the code. For example, having access to your value in memory allows you to change the original value from different parts of your code without the need to copy your value around.
In Go, to create a pointer, you just append * in front of the data type of your value. For example, here is a pointer to an int value:
var iptr *int
As we mentioned in the previous section, the zero value of a pointer is nil. The behavior of nil is similar to null in languages like Java, that is, if you try to use a nil pointer, an error will ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access