Chapter Summary

A bit represents the smallest unit of memory, holding either 0 or 1. A byte is the smallest addressable unit of memory, typically containing 8 bits.

A data type instructs the compiler on how to interpret memory contents meaningfully.

C++ provides several fundamental data types: floating point numbers, integers, booleans, chars, null pointers, and void.

Void indicates the absence of a type. Its primary use is marking functions that don't return values.

The sizeof operator reports a type's size in bytes.

Signed integers store positive, negative, and zero values. Watch for overflow issues and integer division truncation.

Unsigned integers represent only non-negative values and should be avoided except for bit manipulation tasks.

Fixed-width integers (like std::int32_t) guarantee specific sizes but std::int8_t and std::uint8_t often behave like chars rather than integers.

std::size_t is an unsigned integral type representing object sizes or lengths.

Scientific notation provides a compact way to write large or small numbers. The significant digits are the digits in the significand.

Floating point types represent real numbers with fractional components. Rounding errors occur when storing more significant digits than the type supports. Avoid direct floating point comparisons.

Best Practice
Prefer double over float unless space is critical.

The Boolean type stores either true or false.

If statements conditionally execute code when a condition holds true. An else statement executes when the if condition evaluates to false.

Char stores values interpreted as ASCII characters. Printing a char as an integer requires static_cast.

static_cast explicitly converts values between types. Use it when you intentionally want to perform a potentially lossy conversion.

Key Best Practices

Topic Best Practice
Integers Prefer int when size doesn't matter; use fixed-width types for guaranteed ranges
Unsigned Avoid for quantities; use only for bit manipulation
Floating point Prefer double over float
Comparisons Never compare floating point values for equality
Type conversion Use static_cast for explicit conversions
8-bit types Avoid std::int8_t and std::uint8_t - use 16-bit alternatives