Recall & Review
beginner
What is operator precedence in Rust?
Operator precedence determines the order in which parts of an expression are evaluated. Operators with higher precedence are evaluated before those with lower precedence.
Click to reveal answer
beginner
Which operator has higher precedence: multiplication (*) or addition (+)?
Multiplication (*) has higher precedence than addition (+). So in an expression like 2 + 3 * 4, the multiplication happens first.
Click to reveal answer
beginner
How does parentheses affect operator precedence?
Parentheses change the normal precedence by forcing the expression inside them to be evaluated first, regardless of operator precedence.
Click to reveal answer
intermediate
In Rust, which has higher precedence: logical AND (&&) or logical OR (||)?
Logical AND (&&) has higher precedence than logical OR (||). So && operations are evaluated before || in expressions.
Click to reveal answer
intermediate
What happens if operators have the same precedence?
If operators have the same precedence, Rust evaluates them based on their associativity, usually left to right for most operators.
Click to reveal answer
In Rust, which operator is evaluated first in the expression 5 + 4 * 3?
✗ Incorrect
Multiplication (*) has higher precedence than addition (+), so 4 * 3 is evaluated first.
What does parentheses do in the expression (5 + 4) * 3?
✗ Incorrect
Parentheses force the expression inside to be evaluated first, so 5 + 4 happens before multiplication.
Which operator has higher precedence in Rust: && or ||?
✗ Incorrect
Logical AND (&&) has higher precedence than logical OR (||).
If two operators have the same precedence, how does Rust decide which to evaluate first?
✗ Incorrect
Rust uses associativity rules, usually left to right, to decide evaluation order for operators with the same precedence.
In the expression 10 - 3 - 2, how is the evaluation done?
✗ Incorrect
Subtraction is left-associative, so it evaluates from left to right: (10 - 3) - 2.
Explain operator precedence and how it affects the evaluation of expressions in Rust.
Think about which parts of an expression are calculated first.
You got /4 concepts.
Describe how Rust handles operators with the same precedence and give an example.
Consider how expressions like 10 - 3 - 2 are evaluated.
You got /3 concepts.