# Go operator precedence spells MACAO

yourbasic.org/golang

### Unary operators

Unary operators have the highest precedence and bind the strongest.

### Binary operators (MACAO)

Prio | Operators | Note |
---|---|---|

1 | `*` `/` `%` `<<` `>>` `&` `&^` |
Multiplicative |

2 | `+` `-` `|` `^` |
Additive |

3 | `==` `!=` `<` `<=` `>` `>=` |
Comparison |

4 | `&&` |
And |

5 | `||` |
Or |

Binary operators of the same precedence associate from **left to right**.

### Statement operators

The `++`

and `- -`

operators **form statements** and fall outside the operator hierarchy.

### Examples

Expression | Evaluation order |
---|---|

`x / y * z` |
`(x / y) * z` |

`*p++` |
`(*p)++` |

`^a >> b` |
`(^a) >> b` |

`1 + 2*a[i]` |
`1 + (2*a[i])` |

`m == n+1 && <-ch > 0` |
`(m == (n+1)) && ((<-ch) > 0)` |