Operators
Explore how Go's operator precedence differs from other languages and understand the unique treatment of increment, decrement, ternary absence, and bitwise operations. Learn how these affect writing clearer and less error-prone Go code within the context of data types.
We'll cover the following...
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:
...