Skip to main content
The * operator in Go is a context-dependent token that serves three distinct syntactic and semantic functions: pointer indirection (dereferencing), pointer type declaration, and arithmetic multiplication.

1. Pointer Indirection (Dereferencing)

As a unary prefix operator, * performs indirection on a pointer operand. It resolves the memory address held by the pointer and yields the underlying value. The result of a pointer indirection is addressable, meaning it can be used both to evaluate the value at an address and to assign a new value to mutate the underlying memory. If the pointer operand evaluates to nil, evaluating or assigning to the indirection will cause a runtime panic.

2. Pointer Type Declaration

In type declarations, variable declarations, and function signatures, * acts as a type constructor. It denotes a composite type that represents a pointer to a specific base type. The base type dictates the memory layout, size, and alignment of the data being pointed to.

3. Arithmetic Multiplication

As a binary infix operator, * performs arithmetic multiplication. It requires two numeric operands of identical types (or untyped constants that can be implicitly converted to a common type) and yields a product of that same type.
Tired of Poor Go Skills? Fix That With Deep Grasping!Learn More