Article by Ayman Alheraki on January 11 2026 10:37 AM
The “Hello World” program is the canonical starting point for learning any programming language. It serves as a simple example to illustrate the basic syntax for outputting text to the console, and it often reveals fundamental language concepts like compilation, program structure, and standard library usage.
This section compares the “Hello World” program in both Modern C++ (using C++17/20 conventions) and Rust (edition 2021), providing insight into language syntax, compilation, and execution.
int main() { std::cout << "Hello, World!" << std::endl; return 0;}
#include
int main(): The entry point of the C++ program, returning an integer status code to the operating system. return 0; conventionally means successful execution (ISO C++ Standard).
std::cout << "Hello, World!" << std::endl;: Streams the string literal "Hello, World!" to the standard output, followed by a newline (std::endl). The std:: prefix specifies the use of the standard namespace (cplusplus.com).
Compiled with a C++ compiler such as GCC, Clang, or MSVC using a command like:
fn main() { println!("Hello, World!");}
Modern C++ compilers fully support the standard library and optimizations, ensuring the program is efficient with minimal startup overhead (GCC 12 release notes).
fn main(): The entry point of the Rust program, which returns the unit type () implicitly. Rust functions are declared with fn (Rust Reference).
println!("Hello, World!");: Macro that prints text to the console, automatically appending a newline. Macros in Rust use an exclamation mark !. The macro provides formatting support similar to printf but with compile-time checks (Rust Standard Library).
Compiled with the Rust compiler rustc:
xxxxxxxxxxrustc hello.rs./hello
The Rust compiler performs aggressive optimizations and ensures memory safety at compile time. The latest Rust 1.70 release (2023) continues to improve compile times and executable performance (Rust Blog).
| Aspect | C++ “Hello World” | Rust “Hello World” |
|---|---|---|
| Program entry point | int main() with explicit return | fn main() returns unit type implicitly |
| Output syntax | Stream-based std::cout and<< operator | Macro-based println! with formatting |
| Header inclusion | Requires explicit #include | No header inclusion, core macros are built-in |
| Memory safety | Manual memory safety, not an issue for simple output | Guaranteed memory safety, even in complex programs |
| Compilation command | g++ -std=c++17 or equivalent | rustc |
| Language paradigm | Multi-paradigm: procedural, object-oriented, generic | Multi-paradigm: procedural, functional, ownership-based |
| Error handling | Return codes from main and exceptions | Implicit unit return; error handling via Result and macros |
https://en.cppreference.com/w/cpp/header/iostream
http://www.cplusplus.com/doc/tutorial/basic_io/
https://isocpp.org/std/the-standard
https://doc.rust-lang.org/reference/items/functions.html
https://doc.rust-lang.org/std/macro.println.html
https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html