0
0
Rustprogramming~20 mins

Operator precedence in Rust - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Operator Precedence Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2: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);
}
A11
BError
C10
D14
Attempts:
2 left
๐Ÿ’ก Hint
Remember that multiplication (*) has higher precedence than addition (+).
โ“ Predict Output
intermediate
2: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);
}
Atrue
Bfalse
CCompilation error
Dpanic at runtime
Attempts:
2 left
๐Ÿ’ก Hint
Logical AND (&&) has higher precedence than logical OR (||).
โ“ Predict Output
advanced
2: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);
}
Afalse
Bpanic at runtime
Ctrue
DCompilation error
Attempts:
2 left
๐Ÿ’ก Hint
Bitwise AND (&) has higher precedence than equality (==).
โ“ Predict Output
advanced
2: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);
}
A20
B14
CError: cannot assign to immutable variable
D10
Attempts:
2 left
๐Ÿ’ก Hint
Multiplication happens before addition assignment.
โ“ Predict Output
expert
2: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);
}
A9
BCompilation error
C16
D24
Attempts:
2 left
๐Ÿ’ก Hint
Addition (+) has higher precedence than bitwise shift (<<).