Home » First Rust Program

First Rust program

Let’s write the simple program in Rust language. Now, open the notepad file and write the following code:

Output:

Hello, world!  

main(): The main() function is always the first code in every Rust executable code. The main() function is enclosed in curly braces{}. The main() function does not contain any parameter as well as it does not return any value.

println!: It is a Rust macro. If it calls the function, then it does not contain ‘!’.

“Hello World”: It is a string passed as a parameter to the println!, and the string is printed to the console.

Procedure to create, compile and run the program

1. Open the notepad file and write the code in a notepad file.

2. Save the file with .rs extension.

First Rust program

3. Open the command prompt

4. Set the path of the directory. Suppose the project is located in D drive.

First Rust program

5. Compile the above program using the rustc command.

First Rust program

6. Finally, run the program by using the command filename.exe.

First Rust program


Next TopicRust if- else

You may also like