Introduction
Writing your first Rust program helps you learn how to create and run simple code. It shows you how Rust works and how to see results on your screen.
Writing your first Rust program helps you learn how to create and run simple code. It shows you how Rust works and how to see results on your screen.
fn main() {
println!("Hello, world!");
}fn main() defines the main function where the program starts.
println!("text") prints text to the screen with a new line.
fn main() {
println!("Hello, Rust!");
}fn main() {
println!("Sum of 2 + 3 is {}", 2 + 3);
}fn main() {
println!("Welcome to Rust programming.");
}This is the simplest Rust program. It prints "Hello, world!" to the screen.
fn main() {
println!("Hello, world!");
}Every Rust program starts with a main function.
Use println! to show messages on the screen.
Remember to save your file with .rs extension before running.
Rust programs start with fn main().
Use println! to print messages.
Running your first program helps you check your setup and learn basics.
main function.fn main().fn main() function -> Option Aprintln! to print text with a newline.println!("Hello, world!"); is valid Rust syntax for printing with a newline.fn main() {
println!("{}", 5 + 3);
}{} inside the string is a placeholder for the value following the string.5 + 3 evaluates to 8, which replaces the {}.fn main() {
println!("Hello, world!")
}println!("Hello, world!") line is missing a semicolon at the end.{} as a placeholder and variables are passed after the string.println!("Hello, {}!", name); to print the variable's value.Pass the test and this pattern moves unknown