ProgrammingHardProduct-company MCQ pattern

What is printed? (Assume a 64-bit LP64 ABI, where long is 8 bytes.)

What is printed? (Assume a 64-bit LP64 ABI, where long is 8 bytes.)
long fact(int n) {
    return n <= 1 ? 1 : n * fact(n - 1);
}
int main(void) {
    printf("%ld", fact(13));
}
  1. A. 1932053504
  2. B. Compilation error: fact(13) exceeds long range
  3. C. 6227020800
  4. D. Undefined behaviour: int multiplication overflows before reaching long precision

Correct answer: C. 6227020800

In `n * fact(n-1)`, fact(n-1) is a long, so the usual arithmetic conversions promote n (int) to long before multiplying — the entire computation happens in 64-bit long precision, never truncating to 32-bit int. 13! = 6227020800, which fits comfortably in a long, so that exact value is printed with no overflow.

More C Programming questions

Exams that ask this topic