In this tutorial you will learn about the Rust Hello World Program and its application with practical example.
Rust Hello World Program
As usual we will start learning Rust programming by creating “Hello, world!” program. The “Hello, world!” program is a simplest program that will display some text on the screen. The “Hello, world!” program is a simple yet complete program for beginners that illustrates the basic syntax of Rust programming language. The “Hello, world!” program gives you a way to test systems and programming environment.
This tutorial will guide you through writing a basic “Hello, World!” program in Rust.
Creating Hello World Program
Step 1:- Create a file called “hello.rs” using a text editor program of your choice. The .rs file extension is used to specify Rust file.
Step 2:- Let’s open the “hello.rs” file that we created, and put the following line of code in it and save it.
1 2 3 4 |
fn main() { println!( "Hello, world!"); } |
The println() is a Rust macro that emits formatted text to the console.
Step 3:- Now, open terminal or command prompt and switch to the folder where our “hello.rs” file is saved. Now, compile the program by typing the following command –
1 |
rustc hello.rs |
Step 4 :- After the program is complied, we can run using the filename.exe
1 |
hello.exe |
Now, when the program is executed it will print “Hello, world!” as below –
Output:-
1 |
Hello, world! |