Operators
Learn about operators in Go.
We'll cover the following...
Operator precedence
Go operator precedence is different than in other languages:
| Precedence | Operator | 
| 5 | *, /, %, <<, >>, &, &^ | 
| 4 | +, -, |, ^ | 
| 3 | ==, !=, <, <=, >, >= | 
| 2 | && | 
| 1 | || | 
Compare it to C based languages:
| Precedence | Operator | 
| 10 | *, /, % | 
| 9 | +, - | 
| 8 | <<, >> | 
| 7 | <, <=, >, >= | 
| 6 | ==, != | 
| 5 | & | 
| 4 | ^ | 
| 3 | | | 
| 2 | && | 
| 1 | || | 
This can lead to different results for the same expression:
In Go:
Press +  to interact
Go (1.16.5)
package mainimport "fmt"func main() {fmt.Println(1 << 1 + 1) // (1 << 1) + 1 = 3}
 ...
 Ask