Concept Flow - main function and entry point
Program starts
Look for main()
Execute main() body
Program ends
Rust programs start by running the main() function, which is the entry point where execution begins and ends.
fn main() {
println!("Hello, world!");
}| Step | Action | Code Line | Output |
|---|---|---|---|
| 1 | Program starts and looks for main() | fn main() { | |
| 2 | Enter main function | fn main() { | |
| 3 | Execute println! macro | println!("Hello, world!"); | Hello, world! |
| 4 | End of main function reached | } | |
| 5 | Program terminates |
| Variable | Start | After main start | After println! | Final |
|---|---|---|---|---|
| No variables | - | - | - | - |
Rust programs start execution at the main() function. main() is the required entry point. Code inside main() runs sequentially. Program ends when main() finishes. Use println! to print output inside main().