When do Go’s pointers dereference themselves

The selector expression (e.g. x.f) does that:

Selectors automatically dereference pointers to structs. If x is a pointer to a struct,
x.y is shorthand for (*x).y; if the field y is also a pointer to a struct, x.y.z is
shorthand for (*(*x).y).z, and so on. If x contains an anonymous field of type *A, where
A is also a struct type, x.f is a shortcut for (*x.A).f.

The definition of the index expressions specifies that an array pointer may be indexed:

For a of pointer to array type:

  • a[x] is shorthand for (*a)[x]

Leave a Comment