CREATE YOU FIRST HELLO WORLD PROGRAM IN RUST

CONTENTS

INTRODUCTION

So, we have already installed the RUST PACKAGE in our computer and you must be very excited to start programming without any further delay.

RUST is a great language with faster development.

CLICK HERE TO LEARN THE INSTALLATION OF RUST IN WINDOWS

It is a standard practice to start the learning of any programming language with the HELLO WORLD program in which we simply print or show the HELLO WORLD as output.

In this article, we’ll learn the steps to create our first HELLO WORLD program in RUST.



WRITING THE HELLO WORLD CODE IN RUST

Let us write the code first and then try to understand the structure.

Follow the steps to write the HELLO WORLD code in Rust

  • Open NOTEPAD or any other text editor as per your choice.
  • Enter the following code.
//gyankosh.net This is your first code. Double // signifies the comments. Anything written after these won't be taken as code.
fn main() {
    println!("Hello, world!");
}
  • Save this file with any name. We saved it with the name hello_world.rs .

.rs is the extension given to the files containing RUST CODE.

Your code is ready to be compiled and run.



COMPILING THE CODE

To compile the code, we need to use the command line tool.

  • Open the command prompt or press WINDOWS+RUN and type cmd in the RUN dialog box.
  • Press enter.
  • The command prompt will open.
  • Reach the folder where you have stored the file containing the code.

REFER THIS PAGE TO ROAM AROUND AND USE THE BASIC FUNCTIONALITIES IN COMMAND PROMPT.

After you have reached the folder or directory where your rust code is stored, enter the command as

rustc filename.rs

For our example, we’ll use rustc hello_world.rs

It’ll compile the code and create a few files.

The files after the compilation will be ONE .EXE, ONE .PDB and one .RS file [.RS file is the one already created by us ].

For our example, we’ll get hello_world.exe, hello_world.pdb


DESCRIPTION OF THE CODE

The code used is

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

fn main(){ } is the main function in RUST and each and every code will lie inside this function.

It means every code will be

fn(main){

code

code

code

}

Println will print the text passed into the braces as we used Hello, world! inside this.

You can enter any text to print it.

We’ll learn more as we go inside the RUST step by step.


RUNNING THE CODE

After successful compilation, simply type hello_world and it’ll show the output.

RUNNING HELLO WORLD PROGRAM

So, in this article, we learnt about the very basic HELLO WORLD program.