Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC++constexpr consteval constinitSingle-choice MCQ

A `constexpr` function body contains `a / b`. Calling it with `b == 0` at runtime is fine, but the same call in a constant-expression context makes the program ill-formed. What general rule explains this?

constexpr int div(int a, int b) { return a / b; } int main(int argc, char**) { int r = div(10, argc); // runtime: fine constexpr int c = div(10, 0); // compile time: ill-formed }