Understand main and println!
Quick answer
In an ordinary Rust executable, fn main() defines the entry function. Its braces contain the code that runs when the program starts. println! is a macro that prints formatted text followed by a newline. The exclamation mark is part of the macro call syntax.
Formatting and comments
The first argument is a format string; each {} placeholder accepts a corresponding value. A line starting with // is a comment, ignored during ordinary execution. Comments explain the intent, while instructions perform the task.
fn main() { // Print the title and room number. println!("Reading room"); println!("Room {}", 4);}Expected stdout (not executed):
Reading roomRoom 4The comment does not appear in the output.
Expected stdout (not executed):
3 of 5 completedThe first placeholder receives 3 and the second receives 5.
Common mistake
println("Hello") is not a call to the standard println! macro. Also match the number of format placeholders to the supplied values.
Try it yourself
Print a title and then a progress line containing two different numbers.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Understand main and println! — practice quiz
Choose one answer per question, then review the explanation.
What does `// Print a label` do in a Rust source file?
What does `println!("{} / {}", 4, 9);` print?
Which call uses two placeholders and two arguments correctly?