0
0
Rustprogramming~5 mins

Writing first Rust program

Choose your learning style9 modes available
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.

When you want to learn how to write and run Rust code for the first time.
When you want to check if your Rust setup on your computer is working.
When you want to understand the basic structure of a Rust program.
When you want to print messages or simple results to the screen.
When you want to start practicing Rust programming step-by-step.
Syntax
Rust
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.

Examples
This prints a simple greeting message.
Rust
fn main() {
    println!("Hello, Rust!");
}
This prints a message with a calculated value inside.
Rust
fn main() {
    println!("Sum of 2 + 3 is {}", 2 + 3);
}
This prints a welcome message to the user.
Rust
fn main() {
    println!("Welcome to Rust programming.");
}
Sample Program

This is the simplest Rust program. It prints "Hello, world!" to the screen.

Rust
fn main() {
    println!("Hello, world!");
}
OutputSuccess
Important Notes

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.

Summary

Rust programs start with fn main().

Use println! to print messages.

Running your first program helps you check your setup and learn basics.