Challenge - 5 Problems
Rust Expression 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 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);
}Attempts:
2 left
๐ก Hint
Remember the order of operations: multiplication before addition and subtraction.
โ Incorrect
The expression is evaluated as 5 + (10 * 2) - 3 = 5 + 20 - 3 = 22.
โ Predict Output
intermediate2: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);
}Attempts:
2 left
๐ก Hint
Calculate inside parentheses first, then multiply.
โ Incorrect
First, (4 + 3) = 7 and (4 - 3) = 1. Then multiply: 7 * 1 = 7.
โ Predict Output
advanced2: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);
}Attempts:
2 left
๐ก Hint
Remember integer division and remainder operations.
โ Incorrect
Integer division 10 / 3 = 3, then 3 * 3 = 9, plus remainder 10 % 3 = 1, total 10.
โ Predict Output
advanced2: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);
}Attempts:
2 left
๐ก Hint
Evaluate NOT first, then AND, then OR.
โ Incorrect
x && !y is true && true = true; y && !x is false && false = false; true || false = true.
โ Predict Output
expert2: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);
}Attempts:
2 left
๐ก Hint
Casting changes types before multiplication. Check the order carefully.
โ Incorrect
x as f64 = 7.0, y = 2.5, so 7.0 * 2.5 = 17.5.