About this question

Compile-Time Factorial with constexpr

Easy · template_metaprogramming · Quant Developer interview question · constexpr, compile-time, factorial, c++14, c++17, static-assert

Combinatorial coefficients, used in models like binomial options pricing, often require factorial calculations. Using constexpr functions to compute these values at compile time embeds the results directly into the binary, eliminating runtime overhead. This technique is fundamental for creating high-performance C++ applications in quantitative finance. Task Implement the constexpr function factorial(int n) that computes the factorial of a non-negative integer n. The function must return an unsi