Recall & Review
beginner
What values can a Boolean type hold in Rust?
A Boolean type in Rust can hold only two values: true or false.
Click to reveal answer
beginner
How do you declare a Boolean variable in Rust?
You declare a Boolean variable using <code>let</code> keyword and specify the type as <code>bool</code>. Example: <code>let is_active: bool = true;</code>Click to reveal answer
intermediate
What is the default Boolean value if you do not initialize it in Rust?
In Rust, variables must be initialized before use. There is no default value for Boolean variables; you must assign
true or false explicitly.Click to reveal answer
beginner
How can Boolean values be used in control flow in Rust?
Boolean values control the flow of programs using
if statements, while loops, and other conditional expressions. For example: if is_active { println!("Active"); }Click to reveal answer
intermediate
Can you convert other types to Boolean in Rust directly?
Rust does not allow implicit conversion to Boolean. You must explicitly compare or convert values to get a Boolean. For example, <code>let is_zero = x == 0;</code> returns a Boolean.Click to reveal answer
Which of the following is a valid Boolean value in Rust?
✗ Incorrect
Rust Boolean values are only
true or false. Numbers or strings are not valid Boolean values.How do you declare a Boolean variable named
flag set to false?✗ Incorrect
Both A (with type inference) and D (with explicit
: bool) correctly declare a Boolean variable in Rust.What happens if you try to use an uninitialized Boolean variable in Rust?
✗ Incorrect
Rust requires variables to be initialized before use, so using an uninitialized Boolean causes a compile-time error.
Which statement correctly uses a Boolean in an if condition?
✗ Incorrect
Rust uses
if condition { } syntax. Option C is correct and idiomatic.Can you write
let b: bool = 1; in Rust?✗ Incorrect
Rust does not allow implicit or explicit conversion from integer to Boolean. You must use comparisons to get a Boolean.
Explain how Boolean types are used in Rust and how you declare them.
Think about how you create a true/false variable and what rules Rust has about initialization.
You got /4 concepts.
Describe how Rust handles conversions to Boolean and why implicit conversion is not allowed.
Consider how Rust keeps your code safe by requiring clear true/false expressions.
You got /4 concepts.