Search⌘ K

Precedence and Associativity

Explore how Rust evaluates expressions by learning operator precedence and associativity. Understand which operators execute first and how expressions with multiple operators are parsed to write effective Rust code.

Precedence

The precedence of an operator determines which operation is performed first in an expression with more than one operators.

Operators are listed below in the order of their precedence from highest to lowest :

  • Unary
    • Logical/Bitwise NOT - !
    • Derereference - *
    • Borrow - &, &mut
  • Binary
    • Typecast - as
    • Multiplication- *,Division - /, Remainder - %
    • Addition -+,
...