Skip to main content
The *= (multiplication assignment) operator is a compound assignment operator that multiplies the left-hand side (LHS) operand by the evaluated right-hand side (RHS) expression and assigns the resulting product back to the LHS operand. According to the Go specification, it serves as syntactic sugar for explicit multiplication and assignment, with the RHS implicitly enclosed in parentheses to preserve operator precedence.

Technical Characteristics

1. Operand Requirements
  • LHS Assignability: The left-hand operand must be an assignable expression. In Go, this means the LHS must be either an addressable value (such as a variable, pointer indirection, slice element, or struct field) or a map index expression. While map elements are explicitly unaddressable (you cannot take their address using &m[key]), the language makes a specific exception allowing map index expressions on the left-hand side of assignments. The LHS cannot be a literal or a constant.
  • Numeric Types: The *= operator is strictly defined for numeric types. Both operands must resolve to integers, floating-point numbers, or complex numbers.
2. Type Compatibility Go’s strict typing system dictates that the LHS and RHS must be of the exact same type. If the RHS is an untyped constant, it must be implicitly convertible to the type of the LHS.
3. Evaluation Order and Precedence During execution, Go evaluates the LHS and RHS expressions before performing the multiplication and subsequent assignment. If the LHS involves a function call, pointer dereference, or index expression to determine the target memory location, that evaluation occurs exactly once. Furthermore, because the compound assignment evaluates as LHS = LHS * (RHS), any lower-precedence operators in the RHS expression are evaluated before the multiplication.
Tired of Poor Go Skills? Fix That With Deep Grasping!Learn More