Search⌘ K

Exercises

Explore practical exercises that help you understand function definition, function calls, and program compilation in Rust. Learn to fix compile errors, create helper functions, and use macros effectively to produce specific program output. This lesson sharpens your skills in writing and manipulating Rust functions for better programming fluency.

Exercise 1

Will the program compile? Why, or why not? If not, try to fix it.

Rust 1.40.0
fn main() {
42
}

Exercise 2

Will the program compile? Why or why not? If not, try to fix it.

Rust 1.40.0
fn main() {
println!("{}", 42)
}

Exercise 3

Technical Quiz
1.

What is the output of this program?

fn main() {
    let x = 5;
    {
        let x = 6;
        println!("First time: {}", x);
    }
    println!("Second time: {}", x);
}
A.

First time: 6

Second time: 6

B.

First time: 6

Second time: 5

C.

First time: 5

Second time: 5


1 / 1

Exercise 4

Add the helper functions ...