The entry point of a Rust program is the main function. It is where the program starts running.
Click to reveal answer
beginner
How do you define a function in Rust?
You define a function in Rust using the fn keyword, followed by the function name and parentheses. For example: fn greet() {}
Click to reveal answer
intermediate
What is the purpose of the use keyword in Rust?
The use keyword brings modules, functions, or types into scope so you can use them without writing the full path every time.
Click to reveal answer
intermediate
What is a module in Rust and why is it useful?
A module is a way to organize code into separate namespaces. It helps keep code clean and manageable by grouping related functions, structs, and other items.
Click to reveal answer
beginner
How do you write comments in Rust?
Single-line comments start with //. Multi-line comments are enclosed between /* and */. Comments help explain code to others or yourself.
Click to reveal answer
What keyword starts the main function in a Rust program?
Afunction
Bmain
Cstart
Dfn
✗ Incorrect
The fn keyword is used to define any function, including main.
Which symbol is used to write a single-line comment in Rust?
A//
B#
C/*
D<!--
✗ Incorrect
Single-line comments in Rust start with //.
What does the use keyword do in Rust?
ADefines a new function
BImports code into scope
CStarts the program
DDeclares a variable
✗ Incorrect
The use keyword brings modules or items into scope for easier access.
Which of these is a correct way to define a function named hello in Rust?
Afn hello() {}
Bfunction hello() {}
Cdef hello() {}
Dfunc hello() {}
✗ Incorrect
Rust uses fn to define functions.
Why are modules useful in Rust?
ATo speed up the program
BTo declare variables
CTo organize code into namespaces
DTo write comments
✗ Incorrect
Modules help organize code by grouping related items into namespaces.
Explain the basic structure of a Rust program including the main function and modules.
Think about where the program starts and how code is grouped.
You got /5 concepts.
Describe how comments are written in Rust and why they are important.
Comments help others understand your code.
You got /5 concepts.
Practice
(1/5)
1. In a Rust program, where does the execution start?
easy
A. At the last line of the file
B. Inside the main function
C. Inside a function named start
D. At the first line of the file outside any function
Solution
Step 1: Understand Rust program entry point
Rust programs always begin execution from the main function.
Step 2: Check other options
Code outside functions or other function names like start are not entry points.
Final Answer:
Inside the main function -> Option B
Quick Check:
Rust starts at main() [OK]
Hint: Rust always runs code starting from main() [OK]
Common Mistakes:
Thinking code outside main() runs first
Assuming a function named start() runs automatically
Believing execution starts at the last line
2. Which of the following is the correct way to write the main function in Rust?
easy
A. function main() { println!("Hello, world!"); }
B. main() { println!("Hello, world!"); }
C. fn main() { println!("Hello, world!"); }
D. def main() { println!("Hello, world!"); }
Solution
Step 1: Identify Rust function syntax
Rust functions start with fn, followed by the name and parentheses.
Step 2: Check each option
Only fn main() { println!("Hello, world!"); } uses fn main() correctly; others use wrong keywords.
Final Answer:
fn main() { println!("Hello, world!"); } -> Option C
The main function starts with fn main() { but never closes with a }.
Step 2: Verify other syntax
The semicolon after println! is present, comment syntax is correct, and println! is spelled correctly.
Final Answer:
Missing closing brace '}' for main function -> Option D
Quick Check:
Every { needs a matching } [OK]
Hint: Count opening and closing braces carefully [OK]
Common Mistakes:
Forgetting to close function with }
Confusing comment syntax with errors
Missing semicolon errors instead of braces
5. You want to add a comment explaining why your Rust program prints "Hello". Which is the correct way to add a single-line comment inside the main function?
hard
A. // This prints Hello
println!("Hello");
B. # This prints Hello
println!("Hello");
C. /* This prints Hello */ println!("Hello");
D. println!("Hello");
Solution
Step 1: Identify Rust comment syntax
Rust uses // for single-line comments and /* */ for block comments.
Step 2: Check each option
Only // This prints Hello
println!("Hello"); uses Rust's single-line comment syntax correctly; /* ... */ is a block comment, # is Python-style, and <!-- ... --> is HTML.
Final Answer:
// This prints Hello
println!("Hello"); -> Option A
Quick Check:
Single-line comments start with // [OK]
Hint: Use // for single-line comments in Rust [OK]
Common Mistakes:
Using # or for comments
Confusing block comments with single-line
Placing comments inside println! macro
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.