Article by Ayman Alheraki on January 11 2026 10:37 AM
int, float, boolPrimitive types are the fundamental data types provided by a programming language to represent basic values. They form the building blocks of all complex data structures and variables. This section compares three core primitive types — int, float, and bool — as implemented in Modern C++ and Rust, highlighting their characteristics, ranges, and usage.
int)In C++, the keyword int refers to a signed integer type whose size is implementation-dependent but typically 32 bits on modern desktop and server platforms. The C++ standard guarantees a minimum size of 16 bits (ISO C++ Standard, latest draft, cppreference).
C++ provides a family of integer types:
Signed: int, short, long, long long
Unsigned: unsigned int, etc.
The exact size and ranges can be checked using <climits>, e.g., INT_MAX (cppreference limits).
Modern C++ (C++11 and later) offers fixed-width integer types via <cstdint> such as int32_t and uint64_t for guaranteed sizes across platforms (ISO C++11 Standard).
Typical range of a 32-bit int: −2,147,483,648 to 2,147,483,647.
Rust has explicitly sized integer types such as i32, i64, u32, u64 reflecting the number of bits and signedness. The int keyword does not exist in Rust, but isize and usize represent pointer-sized signed and unsigned integers respectively, varying by platform (Rust Reference).
Default integer literals without suffix default to i32 if type inference is needed (Rust book).
Rust integers provide defined overflow behavior in debug builds (panic on overflow) and wrapping behavior in release builds, improving safety and performance tradeoffs (Rust Overflow documentation).
Rust enforces explicit casting between integer types, reducing implicit conversion errors common in C++ (Rust casting).
float)C++ provides floating-point types as per IEEE-754 standards: float (single precision), double (double precision), and long double (extended precision depending on the platform) (IEEE-754, cppreference).
float typically represents a 32-bit single precision floating-point number, with approximately 7 decimal digits of precision and exponent range of ±38 (IEEE-754 Single Precision).
C++ supports floating-point literals and provides functions and constants via <cmath> and <limits>.
C++20 introduced new features improving floating-point support and constexpr capabilities (ISO C++20 Standard).
Rust provides f32 and f64 as IEEE-754 compliant single and double precision floating-point types, respectively (Rust Reference).
Like integers, floating-point literals default to f64 unless otherwise specified (Rust book).
Rust’s standard library offers methods for floating-point arithmetic, comparison, and manipulation through inherent methods and traits (Rust std::f32).
Rust emphasizes safe floating-point usage with no implicit coercions and explicit handling of NaN, infinity, and precision limits (Rust RFC 1665).
bool)The C++ bool type represents Boolean values: true or false. It was formally introduced in C++98, distinct from integer types (cppreference).
bool occupies 1 byte typically, but its exact size is implementation-defined.
Conversion rules allow implicit conversion between bool and integers (true → 1, false → 0), which sometimes leads to subtle bugs (Herb Sutter, C++ Core Guidelines).
Rust has a dedicated bool type representing two values: true and false.
Unlike C++, Rust does not allow implicit conversions between bool and integers, enforcing stronger type safety and preventing common bugs (Rust Reference).
The bool type occupies 1 byte.
| Aspect | C++ | Rust |
|---|---|---|
| Integer type | int (platform dependent size), fixed-width via <cstdint> | Explicit sized: i32, u64, isize, usize |
| Integer default | No literal default; type inferred or specified | Integer literals default to i32 |
| Integer overflow | Undefined behavior or wrapping (UB in release) | Panic on overflow in debug, wrapping in release |
| Float type | float (32-bit), double (64-bit), long double (platform-dependent) | f32 (32-bit), f64 (64-bit) |
| Float default | Depends on context, usually double | f64 default for float literals |
| Boolean type | bool, implicit int conversions allowed | bool, no implicit conversions |
| Memory size | Varies, often 4 bytes for int, 1 byte for bool | Explicit sizes; predictable |
ISO C++ Standard latest drafts https://isocpp.org/std/the-standard
C++ Primitive Types — cppreference https://en.cppreference.com/w/cpp/language/types
C++ Fixed-Width Integer Types https://en.cppreference.com/w/cpp/types/integral_types
IEEE-754 Standard overview https://ieeexplore.ieee.org/document/8766229
Rust Reference — Numeric Types https://doc.rust-lang.org/reference/types/numeric.html
Rust Book — Data Types https://doc.rust-lang.org/book/ch03-02-data-types.html
Rust Reference — Boolean Type https://doc.rust-lang.org/reference/types/bool.html
Herb Sutter’s C++ Core Guidelines (Logic Rules) https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rr-logic
Rust RFC 1665: Float casts https://rust-lang.github.io/rfcs/1665-float-casts.html