thecodex.expert · The Codex Family of Knowledge
C++

Variables and Types

auto never makes C++ dynamically typed — the type is still fixed and fully checked at compile time, auto just lets the compiler write it out for you instead of you typing it by hand.

C++20 / C++23 auto ≠ dynamic typing Last verified:
Canonical Definition

C++ inherits C's numeric types with the same minimum-size guarantees, but adds real improvements: bool has been a genuine built-in type since C++'s earliest days (unlike C, which lacked one until C99), and std::string provides a proper, safe, dynamically-resizing string type — a real class, not just a char array convention. auto, introduced in C++11, tells the compiler to infer a variable's type from its initializer at compile time; the variable's type is fixed at that point exactly as if it had been written explicitly, so auto is purely a convenience for the programmer, never a step toward dynamic typing.

auto: type inference, not dynamic typing

Both declarations end up with the EXACT same type — auto is resolved once, at compile time, from the initializer; count's type can never change afterward, just like an explicitly-typed variable's can't.

C++auto_basics.cpp
int count = 5;        // explicit type
auto count2 = 5;        // auto — but STILL deduced as int, fixed at compile time

// count2 = "hello";   // COMPILE ERROR — count2 is int, always was, always will be

bool: a real type from the start

Unlike C, which had no boolean type at all until C99, C++ has had bool as a genuine built-in type since its earliest versions — no header include ever required.

C++bool_basics.cpp
bool isValid = true;
if (isValid) {
    std::cout << "valid\n";
}

std::string: a real, safe string type

Unlike C's char arrays, std::string manages its own memory, resizes automatically, and provides safe operations like + for concatenation and .length() for size — no manual null-terminator bookkeeping or buffer-size math required.

C++string_basics.cpp
#include <string>

std::string name = "Alice";
std::string greeting = "Hello, " + name + "!";   // safe concatenation, no manual buffer sizing
std::cout << greeting.length() << "\n";            // built-in length tracking

Sources

1
ISO/IEC 14882 (C++ Standard), "auto specifier," cppreference.com/w/cpp/language/auto.