Introduction
Every Rust program needs a clear structure to work correctly. It helps the computer understand what to do step by step.
Every Rust program needs a clear structure to work correctly. It helps the computer understand what to do step by step.
fn main() {
// Your code here
}
fn main() is the starting point of every Rust program.
Curly braces { } contain the code that runs.
fn main() {
println!("Hello, world!");
}// and explain the code but do not run.// This is a comment fn main() { // Print a number println!("Number: {}", 5); }
x store data you can use later.fn main() {
let x = 10;
println!("Value of x is {}", x);
}This simple program shows how to write the main function and print text.
fn main() {
// Print a welcome message
println!("Welcome to Rust programming!");
}Every Rust program must have one main function as the entry point.
Use println! macro to print text to the screen.
Comments help others understand your code and do not affect the program.
Rust programs start running from the main function.
Code inside { } runs step by step.
Use comments to explain your code for yourself and others.
main function.start are not entry points.main function -> Option Bfn, followed by the name and parentheses.fn main() correctly; others use wrong keywords.fn main() {
println!("Start");
{
println!("Inside block");
}
println!("End");
}fn main() {
println!("Hello");
// Missing closing brace
fn main() { but never closes with a }.main function?// for single-line comments and /* */ for block comments.// This prints Hello
println!("Hello"); uses Rust's single-line comment syntax correctly; /* ... */ is a block comment, # is Python-style, and <!-- ... --> is HTML.Pass the test and this pattern moves unknown