How does a constexpr variable differ from a const variable in C++?
Correct answer D. A constexpr variable must be initialised with a constant expression evaluated at compile time
Explanation
Both are read-only, but const only forbids modification; it can be initialised from a run-time value such as user input. constexpr additionally requires the initialiser to be a constant expression, so the value is known at compile time and can be used in array bounds, template arguments and static_assert. Every constexpr variable is implicitly const.
Answer checked How we write and check questions
Discussion