Skip to main content Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.
Navigation Resources
© 2026 BraveProgrammer. All rights reserved.
Your First Program (Hello World) | Rust Fundamentals lesson | BraveProgrammer
Courses / Rust Fundamentals
Your First Program (Hello World) 10 minutes
Your First Program: Hello, World!
The classic "Hello, World!" program demonstrates the fundamental structure of a Rust application. It's simple yet introduces key concepts.
The Minimal Program
fn main () {
println! (\"Hello, world!\");
}
Breaking It Down
The main Function
Where every executable Rust program starts:
fn declares a function
main is special—automatically called when the program starts
Functions without explicit return types implicitly return () (unit type)
The println! Macro println! is a macro (note the !), not a regular function. Macros are more powerful:
println! (\"Hello\"); // Simple print
println!(\"Hello, {}\", name); // String interpolation
println!(\"x = {}, y = {}\", x, y); // Multiple arguments
println!(\"Debug: {:?}\", var); // Debug formatting
Macros are identified by ! and expanded at compile time.
Running Your Program
Exploring println! fn main () {
println! (\"Welcome to Rust!\");
// Variables in output
let name = \"Alice\";
let age = 30;
println!(\"Name: {}, Age: {}\", name, age);
// Debug output
let values = vec![1, 2, 3];
println!(\"Values: {:?}\", values);
// Empty line
println!();
// Expressions
println!(\"2 + 2 = {}\", 2 + 2);
}
Important Details Semicolons : The semicolon matters in Rust:
println! (\"Hello\"); // Statement—no return value
println!(\"Hello\") // Returns unit type (rarely used)
Borrowing : println! borrows values rather than taking ownership, so you can use them afterwards.
Common Mistakes
Forgetting parentheses : println!\"Hello\"; won't compile
Wrong argument count : Missing arguments for placeholders
Unescaped quotes : Inside strings, use \\\" for quotes
What's Next Now you understand the program structure: a main function that executes first and println! for output. You're ready for variables, functions, and control flow.
Make it stick Practice what you've learned 1 quiz · 1 practical test · Optional activities from Rust Fundamentals Browse activities Quiz 1 Course Quiz 3 questions · Pass mark: 70% Start quiz Practical test 1 Hello Rust Program Create a simple Rust program that prints "Hello, Rust!" Start practical test