Hello World

This is the source code of the traditional Hello World program.

  1. // This is a comment, and will be ignored by the compiler
  2. // You can test this code by clicking the "Run" button over there ->
  3. // or if prefer to use your keyboard, you can use the "Ctrl + Enter" shortcut
  4. // This code is editable, feel free to hack it!
  5. // You can always return to the original code by clicking the "Reset" button ->
  6. // This is the main function
  7. fn main() {
  8. // The statements here will be executed when the compiled binary is called
  9. // Print text to the console
  10. println!("Hello World!");
  11. }

println! is a macro that prints text to the
console.

A binary can be generated using the Rust compiler: rustc.

  1. $ rustc hello.rs

rustc will produce a hello binary that can be executed.

  1. $ ./hello
  2. Hello World!

Activity

Click ‘Run’ above to see the expected output. Next, add a new
line with a second println! macro so that the output
shows:

  1. Hello World!
  2. I'm a Rustacean!