0
0
Rustprogramming~20 mins

What is Rust - Practice Questions & Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Rust Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
๐Ÿง  Conceptual
intermediate
2:00remaining
What is the main focus of Rust?

Rust is a programming language designed with a special focus. What is its main focus?

APrimarily for web page styling
BDynamic typing and rapid prototyping
CAutomatic memory management with garbage collection
DMemory safety without using a garbage collector
Attempts:
2 left
๐Ÿ’ก Hint

Think about how Rust handles memory compared to languages like Java or Python.

โ“ Predict Output
intermediate
2:00remaining
What is the output of this Rust code?

Look at this Rust code snippet. What will it print?

Rust
fn main() {
    let x = 5;
    let y = &x;
    println!("{}", y);
}
A5
BCompilation error
CMemory address of x
Dx
Attempts:
2 left
๐Ÿ’ก Hint

Remember that &x is a reference to x, and println! with {} prints the value.

โ“ Predict Output
advanced
2:00remaining
What error does this Rust code produce?

What error will this Rust code cause when compiled?

Rust
fn main() {
    let mut s = String::from("hello");
    let r1 = &s;
    let r2 = &s;
    let r3 = &mut s;
    println!("{} {} {}", r1, r2, r3);
}
ASyntax error: missing semicolon
BCannot borrow `s` as mutable because it is also borrowed as immutable
CNo error, prints: hello hello hello
DUse of moved value `s`
Attempts:
2 left
๐Ÿ’ก Hint

Rust does not allow mutable and immutable references at the same time.

๐Ÿš€ Application
advanced
2:00remaining
How does Rust ensure thread safety?

Rust uses a special system to ensure safe access to data across threads. What is this system called?

AGarbage collection with locks
BManual memory management with pointers
COwnership and borrowing rules enforced at compile time
DDynamic typing with runtime checks
Attempts:
2 left
๐Ÿ’ก Hint

Think about how Rust prevents data races without runtime overhead.

๐Ÿง  Conceptual
expert
2:00remaining
What is the role of the Rust compiler's borrow checker?

What does the borrow checker in Rust do?

AIt enforces rules about references to prevent invalid memory access at compile time
BIt manages garbage collection automatically during runtime
CIt optimizes code for faster execution by reordering instructions
DIt converts Rust code into machine code without checks
Attempts:
2 left
๐Ÿ’ก Hint

Consider how Rust prevents bugs related to references before the program runs.