const: Value cannot be modified at runtime
1const int x = 10; // x cannot be changed2const int* p = &x; // pointer to const int3int* const q = &y; // const pointer to int
constexpr: Evaluated at compile time
1constexpr int factorial(int n) {2 return n <= 1 ? 1 : n * factorial(n - 1);3}45constexpr int x = factorial(5); // computed at compile time6std::array<int, factorial(5)> arr; // size is compile-time constant
Key differences:
const = runtime immutabilityconstexpr = compile-time evaluationconstexpr functions must have simple bodiesconstexpr variables can be used as template arguments