Maps as Pointers

Learn how maps behave like pointers in Go.

We'll cover the following

map is a pointer

While a slice type is a struct (a value type) that has a pointer to an array, a map itself is a pointer. The zero value of a slice is already fully usable. You can use append to add elements and get the slice’s length. A map is different. Go developers would like to make map zero values fully usable, but they couldn’t figure out how to implement that efficiently. The map keyword in Go is an alias for the *runtime.hmap type. Its zero value is nil. A nil map can be read from, but it can’t be written to:

Get hands-on with 1200+ tech skills courses.