loading

First Rust Program

First Rust program

Now let us write a simple Rust program. Now, launch Notepad, and enter the following code in it:

				
					fn main()  
  
    println!("Hello, world!");  
				
			

Output:

				
					Hello, world!
				
			

main(): The first line of code in any Rust executable is always the main() function. Curly braces{} encapsulate the main() function. The function main() does not return any value and does not take any parameters.

println!: It’s a macro in Rust. It doesn’t contain ‘!’ if it calls the method.

“Hello World” : The string is sent to println! as an argument, and the result is printed to the console.

Procedure to create, compile and run the program

1. Open the notepad document and enter the code there.

2. Save the file using the.rs suffix.

First Rust Program -

3. Launch the Command Prompt.

4. Configure the directory’s path. Assume D Drive is where the project is situated.

First Rust Program -

5. Use the rustc command to compile the aforementioned program.

First Rust Program -

6. Lastly, use the command filename.exe to launch the software.

First Rust Program -
Share this Doc

First Rust Program

Or copy link

Explore Topic