0
0
Rustprogramming~10 mins

Why Rust is used - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print a message about Rust's safety.

Rust
fn main() {
    println!("Rust is {} and fast.");
}
Drag options to blanks, or click blank then click option'
Aslow
Bsafe
Ccomplicated
Dunstable
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Choosing 'slow' because of unfamiliarity with Rust's speed.
2fill in blank
medium

Complete the code to declare a variable that cannot be changed in Rust.

Rust
fn main() {
    let [1] = 10;
    // This variable cannot be changed
}
Drag options to blanks, or click blank then click option'
Ax
Bvar x
Cmut x
Dconst x
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'mut x' which makes the variable mutable.
3fill in blank
hard

Fix the error in the Rust code that tries to change an immutable variable.

Rust
fn main() {
    let mut x = 5;
    x = [1];
    println!("x is {}", x);
}
Drag options to blanks, or click blank then click option'
A10
Bx + 1
Cmut x
Dlet x
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Trying to assign 'mut x' or 'let x' inside the function body.
4fill in blank
hard

Fill both blanks to create a Rust function that returns the sum of two numbers.

Rust
fn sum(a: i32, b: i32) -> i32 {
    [1] a + b;
}

fn main() {
    let result = sum(5, 7);
    println!("Sum is: {}", [2]);
}
Drag options to blanks, or click blank then click option'
Aa + b
Breturn
Cresult
Da - b
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'a + b' as a statement without 'return' or missing the variable in print.
5fill in blank
hard

Fill all three blanks to create a Rust program that uses a vector and prints its length.

Rust
fn main() {
    let mut numbers = Vec::new();
    numbers.[1](10);
    numbers.[2](20);
    println!("Length is: {}", numbers.[3]());
}
Drag options to blanks, or click blank then click option'
Apush
Bpop
Clen
Dinsert
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'pop' which removes elements instead of adding.