HelloWorld Example in Rust Language

HelloWorld Example in Rust Language

Here’s a simple “Hello, World!” example in Rust:

page_title -->
fn main() {
    println!("Hello, World!");
}

Here’s what this code does:

  1. fn main() { ... }: This is the entry point of the Rust program. Every Rust program must have a main function.
  2. println!("Hello, World!");: This line prints the “Hello, World!” message to the console. The println! macro is used to format and print text to the standard output.

To run this code:

  1. Save it to a file with a .rs extension, for example, hello.rs.
  2. Open a terminal.
  3. Navigate to the directory where you saved the hello.rs file using the cd command.
  4. Compile the Rust program using the rustc command:
   rustc hello.rs
  1. Run the compiled program:
   ./hello

You should see the “Hello, World!” message printed to the console. This is a basic example of a Rust program, and it demonstrates how to define a main function and print output to the console.


Discover more from PiEmbSysTech

Subscribe to get the latest posts sent to your email.

Leave a Reply

Scroll to Top

Discover more from PiEmbSysTech

Subscribe now to keep reading and get access to the full archive.

Continue reading