What is the difference between constexpr and const?
Last updated
constmeans immutable after initialization, but the value may be computed at runtime (e.g.const int n = readInput();).constexprrequires a compile-time constant, usable for array sizes, template arguments andcaselabels. Everyconstexprvariable is implicitlyconst.constexprfunctions run at compile time with constant arguments and at runtime otherwise.