fork download
  1. #include <iostream>
  2.  
  3. constexpr int factorial(int n) // Everything here is known at compile time
  4. {
  5. return n <= 1 ? 1 : (n * factorial(n - 1));
  6. }
  7.  
  8. int main(void)
  9. {
  10. constexpr int f = factorial(4); // 4 is known at compile time
  11. std::cout << f << std::endl;
  12. return 0;
  13. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
24