Logo
Articles Compilers Libraries Books MiniBooklets Assembly C++ Linux Others Videos
Advertisement

Article by Ayman Alheraki on January 11 2026 10:37 AM

#9 Modern C++ and Rust Programming – A Comparative Educational Guide from Concepts to Applications

#9 Modern C++ and Rust Programming – A Comparative Educational Guide from Concepts to Applications

 

Your First Program

Hello World in both C++ and Rust

Introduction: The Traditional “Hello World”

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.

Hello World in Modern C++

 

  • Explanation:

  • #include : This directive includes the standard input/output stream library, which contains std::cout for console output (cppreference.com).

  • 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).

  • Compilation and Execution:

  • Compiled with a C++ compiler such as GCC, Clang, or MSVC using a command like:

 

  • Modern C++ compilers fully support the standard library and optimizations, ensuring the program is efficient with minimal startup overhead (GCC 12 release notes).

Hello World in Rust

  • Explanation:

  • 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).

  • Compilation and Execution:

  • Compiled with the Rust compiler rustc:

  • 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).

Key Comparative Points

AspectC++ “Hello World”Rust “Hello World”
Program entry pointint main() with explicit returnfn main() returns unit type implicitly
Output syntaxStream-based std::cout and<< operatorMacro-based println! with formatting
Header inclusionRequires explicit #includeNo header inclusion, core macros are built-in
Memory safetyManual memory safety, not an issue for simple outputGuaranteed memory safety, even in complex programs
Compilation commandg++ -std=c++17 or equivalentrustc
Language paradigmMulti-paradigm: procedural, object-oriented, genericMulti-paradigm: procedural, functional, ownership-based
Error handlingReturn codes from main and exceptionsImplicit unit return; error handling via Result and macros

References and Further Reading

  • C++ Standard Library – iostream

https://en.cppreference.com/w/cpp/header/iostream

  • Basic Input/Output in C++

http://www.cplusplus.com/doc/tutorial/basic_io/

  • ISO C++ Standard Documentation

https://isocpp.org/std/the-standard

  • GCC 12 Release Notes

https://gcc.gnu.org/gcc-12/

  • Rust Reference: Functions

https://doc.rust-lang.org/reference/items/functions.html

  • Rust println! Macro

https://doc.rust-lang.org/std/macro.println.html

  • Rust 1.70 Release Notes

https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html

  • Rust Official Website

https://www.rust-lang.org/

Advertisements

Responsive Counter
General Counter
1000733
Daily Counter
2353