const, constexpr & Casts in C++
From the C++ cheat sheet · Variables & Types · verified Jul 2026
const, constexpr & Casts
Immutability and explicit conversions.
cpp
// Quick Reference
const int MAX = 100; // runtime constant
constexpr int SIZE = 10; // compile-time constant
int n = static_cast<int>(3.9); // 3💡 constexpr forces compile-time evaluation; const only promises no mutation.
⚡ Prefer static_cast over C-style casts - it is explicit and easier to grep for.
📌 Mark values const by default; only drop it when you truly need to mutate.
🟢 constexpr values can be used where a compile-time constant is required (array sizes).
constconstexprcasts