> For the complete documentation index, see [llms.txt](https://learning-rust.gitbook.io/book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learning-rust.gitbook.io/book/basics/hello-world.md).

# Hello World

## Hello, World!

```rust
fn main() {
    println!("Hello, world!");
}
```

`fn` means function. main function is the beginning of every Rust program.\
`println!` prints text to the console and its *!* indicate that it’s a [macro](https://doc.rust-lang.org/book/macros.html) instead of a function.

> 💡 Rust files should have .rs file extension and if you’re using more than one word for the file name, follow the [snake\_case](https://en.wikipedia.org/wiki/Snake_case).

* Save above code in `file.rs` , but it can be any name with `.rs` extension.
* Compiling via `rustc file.rs`
* Executing by `./file` on Linux and Mac or `file.exe` on Windows

## Rust Playground

[Rust Playground](https://play.rust-lang.org/) is a web interface for running Rust code.

![Rust Playground](https://1944926124-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAnYl7EM827bPzZzlYG%2F-LAnYpdKmCUxxfbmBvJX%2F-LAnYuGchx4sA326SUF3%2Frust_playground.png?generation=1524504703483436\&alt=media)

## Usages of println!

💯 These are the other usages of println! macro,

```rust
fn main() {
    println!("{}, {}!", "Hello", "world"); // Hello, world!
    println!("{0}, {1}!", "Hello", "world"); // Hello, world!
    println!("{greeting}, {name}!", greeting="Hello", name="world"); // Hello, world!

    println!("{:?}", [1,2,3]); // [1, 2, 3]
    println!("{:#?}", [1,2,3]);
    /*
        [
            1,
            2,
            3
        ]
    */

    // 🔎 format! macro is used to store the formatted STRING
    let x = format!("{}, {}!", "Hello", "world");
    println!("{}", x); // Hello, world!
}
```
