0
0
Rustprogramming~20 mins

Expression evaluation in Rust - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Rust Expression 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 expression?
Consider the following Rust code snippet. What will it print?
Rust
fn main() {
    let x = 5;
    let y = 10;
    let result = x + y * 2 - 3;
    println!("{}", result);
}
A19
B22
C27
D24
Attempts:
2 left
๐Ÿ’ก Hint
Remember the order of operations: multiplication before addition and subtraction.
โ“ Predict Output
intermediate
2:00remaining
What is the value of variable `z` after this code runs?
Look at this Rust code. What value does `z` hold at the end?
Rust
fn main() {
    let x = 4;
    let y = 3;
    let z = (x + y) * (x - y);
    println!("{}", z);
}
A21
B1
C7
D0
Attempts:
2 left
๐Ÿ’ก Hint
Calculate inside parentheses first, then multiply.
โ“ Predict Output
advanced
2:00remaining
What does this Rust code print?
Analyze this Rust code and determine its output.
Rust
fn main() {
    let a = 10;
    let b = 3;
    let c = a / b * b + a % b;
    println!("{}", c);
}
A10
B9
C12
D13
Attempts:
2 left
๐Ÿ’ก Hint
Remember integer division and remainder operations.
โ“ Predict Output
advanced
2:00remaining
What is the output of this Rust code with boolean expressions?
Check the output of this Rust program.
Rust
fn main() {
    let x = true;
    let y = false;
    let result = x && !y || y && !x;
    println!("{}", result);
}
ACompilationError
Bfalse
CSyntaxError
Dtrue
Attempts:
2 left
๐Ÿ’ก Hint
Evaluate NOT first, then AND, then OR.
โ“ Predict Output
expert
2:00remaining
What is the output of this Rust code involving mixed types and casting?
Analyze this Rust code and determine what it prints.
Rust
fn main() {
    let x: i32 = 7;
    let y: f64 = 2.5;
    let z = x as f64 * y;
    println!("{}", z);
}
A17.5
BSyntaxError
C15
D12.5
Attempts:
2 left
๐Ÿ’ก Hint
Casting changes types before multiplication. Check the order carefully.