Go operators
Staying true to its simplistic nature, operators in Go do exactly what you would expect, mainly, they allow operands to be combined into expressions. There are no hidden surprise behaviors with Go operators as there is no support for operator-overloading as found in C++ or Scala. This was a deliberate decision from the designers to keep the semantics of the language simple and predictable.
This section explores the most common operators that you will encounter as you start with Go. Other operators are covered throughout other chapters of the book.
Arithmetic operators
The following table summarizes the arithmetic operators supported in Go.
Operator |
Operation |
Compatible types |
|
Multiplication, division, and subtraction |
Integers, floating points, and complex numbers |
|
Remainder |
Integers |
|
Addition |
Integers, floating points, complex numbers, and strings (concatenation) |
Note that the addition operator, +
, can be applied to strings such as in the expression var i =...