Challenge - 5 Problems
Operator Precedence Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
What is the output of this Rust code involving mixed operators?
Consider the following Rust code snippet. What will it print when run?
Rust
fn main() {
let result = 3 + 4 * 2;
println!("{}", result);
}Attempts:
2 left
๐ก Hint
Remember that multiplication (*) has higher precedence than addition (+).
โ Incorrect
Multiplication happens before addition, so 4 * 2 = 8, then 3 + 8 = 11.
โ Predict Output
intermediate2:00remaining
What is the output of this Rust code with logical and comparison operators?
What does this Rust program print?
Rust
fn main() {
let a = true;
let b = false;
let c = a || b && false;
println!("{}", c);
}Attempts:
2 left
๐ก Hint
Logical AND (&&) has higher precedence than logical OR (||).
โ Incorrect
b && false is false, then a || false is true.
โ Predict Output
advanced2:00remaining
What is the output of this Rust code with mixed bitwise and comparison operators?
Analyze the following Rust code and select the output it produces.
Rust
fn main() {
let x = 5;
let y = 3;
let z = (x & y) == 1;
println!("{}", z);
}Attempts:
2 left
๐ก Hint
Bitwise AND (&) has higher precedence than equality (==).
โ Incorrect
x & y is 1, so 1 == 1 is true.
โ Predict Output
advanced2:00remaining
What is the output of this Rust code with assignment and arithmetic operators?
What does this Rust program print?
Rust
fn main() {
let mut a = 2;
a += 3 * 4;
println!("{}", a);
}Attempts:
2 left
๐ก Hint
Multiplication happens before addition assignment.
โ Incorrect
3 * 4 = 12, then a += 12 means a = 2 + 12 = 14.
โ Predict Output
expert2:00remaining
What is the output of this Rust code with mixed shift and arithmetic operators?
Analyze this Rust code and select the output it produces.
Rust
fn main() {
let a = 1 + 2 << 3;
println!("{}", a);
}Attempts:
2 left
๐ก Hint
Addition (+) has higher precedence than bitwise shift (<<).
โ Incorrect
1 + 2 = 3, then 3 << 3 means shifting 3 left by 3 bits = 3 * 8 = 24.