Pointer types

March 23, 2023

After the long discussion of the details and nuances of struct types, we have a simple topic: Pointers!

Well, maybe it’s not that simple. There are a lot of subtleties that go into the proper use of pointers. But from a specification standpoint, it’s simple. This is the entirety of the section:

Pointer types

A pointer type denotes the set of all pointers to variables of a given type, called the base type of the pointer. The value of an uninitialized pointer is nil.

PointerType = "*" BaseType .
BaseType    = Type .
*Point
*[4]int

The most important thing to note here is that pointers always have a base type, and that the base type may be any other type. Including another pointer. Or an interface:

	var x int
	var y *int
	var z **int
	var youMustBeKidding **********int
	fmt.Println(x, y, z, youMustBeKidding) // Prints: 0 <nil> <nil> <nil>

Quotes from The Go Programming Language Specification Version of December 15, 2022

Share this