0
0
Rustprogramming~10 mins

Program structure in Rust - Interactive Code Practice

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

Complete the code to define the main function in Rust.

Rust
fn [1]() {
    println!("Hello, world!");
}
Drag options to blanks, or click blank then click option'
Arun
Bstart
Cmain
Dbegin
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a different function name instead of main.
Adding parameters to the main function.
2fill in blank
medium

Complete the code to print a message inside the main function.

Rust
fn main() {
    [1]!("Welcome to Rust!");
}
Drag options to blanks, or click blank then click option'
Aprint
Bprintln
Cecho
Dwrite
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using print which does not add a newline.
Trying to use functions instead of macros.
3fill in blank
hard

Fix the error in the function declaration to make it valid Rust code.

Rust
fn main[1] {
    println!("Fixed function");
}
Drag options to blanks, or click blank then click option'
A()
B{}
C<()>
D[]
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Omitting parentheses after the function name.
Using braces {} instead of parentheses.
4fill in blank
hard

Fill both blanks to create a valid Rust program that prints a message.

Rust
fn [1]() {
    [2]!("Hello from Rust!");
}
Drag options to blanks, or click blank then click option'
Amain
Bprint
Cprintln
Dstart
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using incorrect function names.
Using print instead of println.
5fill in blank
hard

Fill all three blanks to define a main function that prints a formatted message.

Rust
fn [1]() {
    [2]!("Number: {}", [3]);
}
Drag options to blanks, or click blank then click option'
Amain
Bprintln
C42
Dprint
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using print instead of println.
Not providing a value for the placeholder.