0
0
Rustprogramming~20 mins

Writing first Rust program - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Rust First Program Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
What is the output of this Rust program?

Look at this Rust code. What will it print when run?

Rust
fn main() {
    let x = 5;
    let y = 10;
    println!("Sum is: {}", x + y);
}
ASum is: 5 + 10
BCompilation error
CSum is: 510
DSum is: 15
Attempts:
2 left
๐Ÿ’ก Hint

Remember, the + operator adds numbers, not strings.

โ“ Predict Output
intermediate
2:00remaining
What will this Rust program print?

Check this Rust code. What is the output?

Rust
fn main() {
    let name = "Alice";
    println!("Hello, {}!", name);
}
AHello, Alice!
BRuntime error
CHello, {}!
DHello, name!
Attempts:
2 left
๐Ÿ’ก Hint

The curly braces {} are replaced by the variable value.

โ“ Predict Output
advanced
2:00remaining
What is the output of this Rust program with a conditional?

What will this Rust program print?

Rust
fn main() {
    let number = 7;
    if number % 2 == 0 {
        println!("Even");
    } else {
        println!("Odd");
    }
}
ACompilation error
BEven
COdd
D7
Attempts:
2 left
๐Ÿ’ก Hint

Check if 7 is divisible by 2 without remainder.

โ“ Predict Output
advanced
2:00remaining
What does this Rust program print with a loop?

Look at this Rust code. What will it print?

Rust
fn main() {
    let mut count = 0;
    while count < 3 {
        println!("Count: {}", count);
        count += 1;
    }
}
A
Count: 0
Count: 1
Count: 2
B
Count: 0
Count: 1
Count: 2
Count: 3
C
Count: 1
Count: 2
Count: 3
DInfinite loop
Attempts:
2 left
๐Ÿ’ก Hint

The loop runs while count is less than 3, starting from 0.

โ“ Predict Output
expert
2:00remaining
What is the output of this Rust program using a function?

What will this Rust program print?

Rust
fn greet(name: &str) {
    println!("Hello, {}!", name);
}

fn main() {
    let user = String::from("Bob");
    greet(&user);
}
AHello, user!
BHello, Bob!
CCompilation error due to borrowing
DRuntime error
Attempts:
2 left
๐Ÿ’ก Hint

Check how the string is passed to the function.