Practice mode C++

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.