Concept Flow - Program structure in Rust
Start
fn main()
Statements inside main
Program ends
Rust programs start with the main function, which runs statements inside it, then ends.
fn main() {
println!("Hello, world!");
}| Step | Action | Code Line | Output |
|---|---|---|---|
| 1 | Program starts | fn main() { | |
| 2 | Enter main function | println!("Hello, world!"); | |
| 3 | Print to screen | println!("Hello, world!"); | Hello, world! |
| 4 | Exit main function | } | |
| 5 | Program ends |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| No variables | - | - | - | - |
Rust programs start with fn main() {
Inside main, statements run in order
Use println! to print text
Program ends after main finishes
No code runs outside functions