0
0
Rustprogramming~20 mins

Relational operators in Rust - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Relational Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2: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);
}
ACompilation error
Bfalse
Ctrue
DRuntime panic
Attempts:
2 left
๐Ÿ’ก Hint
Think about how logical AND works with relational operators.
โ“ Predict Output
intermediate
2: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);
}
ACompilation error
Bfalse
Ctrue
DRuntime panic
Attempts:
2 left
๐Ÿ’ก Hint
Floating-point arithmetic can be tricky due to precision.
โ“ Predict Output
advanced
2: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);
}
ARuntime panic
Bfalse
CCompilation error
Dtrue
Attempts:
2 left
๐Ÿ’ก Hint
Characters are compared by their Unicode values.
โ“ Predict Output
advanced
2: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);
}
ACompilation error
Bfalse
Ctrue
DRuntime panic
Attempts:
2 left
๐Ÿ’ก Hint
Check if Rust allows direct comparison of references with < operator.
๐Ÿง  Conceptual
expert
2:00remaining
Understanding relational operator precedence
Consider this Rust expression: 3 + 4 > 5 && 2 * 2 == 4. What is the value of this expression?
Atrue
Bfalse
CCompilation error
DRuntime panic
Attempts:
2 left
๐Ÿ’ก Hint
Remember operator precedence: arithmetic before relational, then logical.