Start with the idea
A Rust executable begins in fn main(). The braces enclose the statements that run when the program starts. In the example, name is a string slice, and println!("Hello, {name}!") uses it to build a line of text. The exclamation mark matters: println! is a macro, not an ordinary function call. It expands while the program is compiled, so the compiler can check the format string and its arguments before anything runs. If a placeholder is missing an argument, you see a diagnostic instead of a half-working program.
Read the code
fn main() {
let name = "Crabrix";
println!("Hello, {name}!");
}The captured name fills the {name} placeholder. Rust checks that formatting expression during compilation; the resulting line appears on stdout when the program runs.
Practice starter
fn main() {
println!("Hello, Crabrix!");
}
Work through it
Follow the diagram from left to right: source code, a successful compile-time check, then terminal output. The compiler’s messages are not the same as your program’s stdout. A clean build can still produce no output if there is no print call; a failed build cannot run this new version at all. When you change the greeting, predict the exact line you expect before tapping Run. Then compare that prediction with the actual output, including punctuation and spaces. This edit–compile–run–observe cycle is the habit you will use throughout the course.
Start with the three places where text can appear. Your source file contains instructions; the compiler may report an error while checking those instructions; the running program may print a line to standard output. These are separate events. For this example, a successful compile produces a program, and running that program prints exactly Hello, Crabrix! followed by a newline. The code does not display a window or return that greeting as the function's value. println! writes it to the output stream.
Read the punctuation slowly. fn begins a function declaration, main is the entry point, () says it takes no parameters, and { ... } surrounds its body. let name = "Crabrix"; creates a binding. The semicolon ends that statement. Inside the quoted format string, {name} asks formatting to read the binding. Removing the exclamation mark changes the syntax into a call to a function named println, which this program has not defined. Removing the argument or misspelling the captured name causes a compile error. Neither mistake means that a previous successful run printed something new.
Try one change at a time so the cause stays visible. First change only Crabrix to your name and predict the line. Then change Hello to Welcome and predict again. Finally make the format string refer to an unknown binding and read the compiler's primary diagnostic. Restore the code after that experiment. If the output surprises you, check which source version you actually built, whether compilation succeeded, and whether you are reading compiler messages or program output.
Try it
The starter prints one fixed line. Change the greeting and the name in its string, then write down the exact output you predict. Run the project and compare stdout with your prediction. Try a mismatched format placeholder, such as {} with no argument, and notice that compilation stops before a new program runs.
What success looks like: The program exits with code 0 and stdout contains the greeting you predicted. After the deliberately broken placeholder, the compiler identifies the formatting mistake instead of producing new stdout.
Check your understanding
Why does println! end with an exclamation mark?
Reveal the answer
- It returns a Result the caller has to handle
- It is a macro, expanded during compilation
- It writes to stderr rather than stdout
The exclamation mark marks a macro invocation. println! expands at compile time, allowing Rust to check its format string and supplied values before execution.
Learn this lesson with AI
Paste this into Claude, Codex, Cursor or another agent connected to Crabrix Academy. It contains only this lesson’s public details.
I'm learning Rust with Crabrix Academy. Teach me this lesson with the Crabrix Academy tools. Lesson: Hello, Rust (courseId "basics", lessonId "hello-rust") Link: https://crabrix.com/learn/basics/hello-rust/ Goal: Execution begins in fn main(). println! is a compile-time-checked macro that writes a formatted line to stdout when the program runs. Practice: open the starter in the Crabrix Playground (https://crabrix.com/playground/?lesson=basics/hello-rust) and I will write the code there. Explain it step by step for my level, let me write the code myself, give hints before any solution, and do not mark anything as passed: only Crabrix checks do that.