0
0
Rustprogramming~10 mins

Writing first Rust program - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Writing first Rust program
Start program
Call main function
Execute println! macro
Print message to screen
End program
The program starts by calling the main function, which runs the println! macro to print a message, then ends.
Execution Sample
Rust
fn main() {
    println!("Hello, world!");
}
This program prints the message "Hello, world!" to the screen.
Execution Table
StepActionEvaluationResult
1Start programProgram beginsReady to run main()
2Call main functionEnter main()Inside main()
3Execute println! macroPrint stringDisplays: Hello, world!
4End main functionmain() finishesProgram ends
💡 Program ends after main() finishes running
Variable Tracker
VariableStartAfter Step 2After Step 3Final
No variablesN/AN/AN/AN/A
Key Moments - 2 Insights
Why do we use println! instead of a normal function?
println! is a macro in Rust that prints text to the screen. It looks like a function but adds extra features like formatting. See step 3 in the execution table where println! prints the message.
What does fn main() mean?
fn main() defines the main function, which is the starting point of every Rust program. Step 2 shows the program entering main() to run the code inside.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what happens at step 3?
AThe main function is called
BThe program ends
CThe program prints 'Hello, world!' to the screen
DThe program starts
💡 Hint
Check the 'Result' column at step 3 in the execution table
At which step does the program finish running?
AStep 2
BStep 4
CStep 3
DStep 1
💡 Hint
Look at the 'Action' and 'Result' columns to find when main() ends
If we change the message inside println! to "Hi!", what changes in the execution table?
AThe 'Result' at step 3 changes to display 'Hi!'
BStep 2 will change
CThe program will end earlier
DNo changes at all
💡 Hint
Focus on the 'Result' column at step 3 where the printed message appears
Concept Snapshot
fn main() { ... } defines the program start.
Use println!("text") to print messages.
Program runs main(), executes println!, then ends.
println! is a macro for printing.
No variables needed for this simple program.
Full Transcript
This Rust program starts by running the main function. Inside main, the println! macro prints the message 'Hello, world!' to the screen. After printing, the program ends. The println! macro is special because it formats and prints text. The main function is the required entry point for Rust programs. There are no variables in this simple example. The execution table shows each step clearly: starting the program, entering main, printing the message, and ending the program.