Challenge - 5 Problems
Relational Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of chained relational operators
What is the output of this Rust code snippet?
Rust
fn main() {
let a = 5;
let b = 10;
let c = 15;
println!("{}", a < b && b < c);
}Attempts:
2 left
๐ก Hint
Think about how logical AND works with relational operators.
โ Incorrect
The expression a < b && b < c checks if a is less than b AND b is less than c. Both are true, so the output is true.
โ Predict Output
intermediate2:00remaining
Result of comparing floating-point numbers
What will this Rust program print?
Rust
fn main() {
let x = 0.1 + 0.2;
let y = 0.3;
println!("{}", x == y);
}Attempts:
2 left
๐ก Hint
Floating-point arithmetic can be tricky due to precision.
โ Incorrect
Due to floating-point precision, 0.1 + 0.2 is not exactly equal to 0.3, so the comparison returns false.
โ Predict Output
advanced2:00remaining
Output of relational operators with characters
What does this Rust code print?
Rust
fn main() {
let ch1 = 'a';
let ch2 = 'A';
println!("{}", ch1 > ch2);
}Attempts:
2 left
๐ก Hint
Characters are compared by their Unicode values.
โ Incorrect
The Unicode value of 'a' is greater than 'A', so the expression ch1 > ch2 is true.
โ Predict Output
advanced2:00remaining
Relational operator with references
What is the output of this Rust program?
Rust
fn main() {
let x = 10;
let y = 20;
let px = &x;
let py = &y;
println!("{}", px < py);
}Attempts:
2 left
๐ก Hint
Check if Rust allows direct comparison of references with < operator.
โ Incorrect
Rust does not implement the < operator for references to integers directly, so this code causes a compilation error.
๐ง Conceptual
expert2:00remaining
Understanding relational operator precedence
Consider this Rust expression: 3 + 4 > 5 && 2 * 2 == 4. What is the value of this expression?
Attempts:
2 left
๐ก Hint
Remember operator precedence: arithmetic before relational, then logical.
โ Incorrect
3 + 4 is 7, which is greater than 5 (true). 2 * 2 is 4, equal to 4 (true). true && true is true.