Hello World - Rust by Example

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Hello World - Rust By Example 09.10.

2023 12:47

Hello World
This is the source code of the traditional Hello World program.

1 // This is a comment, and is ignored by the compiler.


2 // You can test this code by clicking the "Run" button over there ->
3 // or if you prefer to use your keyboard, you can use the "Ctrl + Enter"
4 // shortcut.
5
6 // This code is editable, feel free to hack it!
7 // You can always return to the original code by clicking the "Reset" button -
8
9 // This is the main function.
10 fn main() {
11 // Statements here are executed when the compiled binary is called.
12
13 // Print text to the console.
14 println!("Hello World!");
15 }

println! is a macro that prints text to the console.

A binary can be generated using the Rust compiler: rustc .

$ rustc hello.rs

rustc will produce a hello binary that can be executed.

$ ./hello
Hello World!

Activity

Click 'Run' above to see the expected output. Next, add a new line with a second
println! macro so that the output shows:

Hello World!
I'm a Rustacean!

https://doc.rust-lang.org/rust-by-example/hello.html Stránka 1 z 1

You might also like