ProgrammingVery hardProduct company OA · code-tracing level

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
// 32-bit signed integers; overflow wraps around (two's complement)
Integer f = 1
for (each i from 1 to 13)
    f = f * i
end for
Print f
  1. A. 6227020800
  2. B. 1932053504
  3. C. -1932053504
  4. D. 479001600

Correct answer: B. 1932053504

12! = 479 001 600 still fits in 32 bits, but 13! = 6 227 020 800 does not. Wrapping keeps the value modulo 2³² = 4 294 967 296: 6 227 020 800 − 4 294 967 296 = 1 932 053 504, which is below 2³¹, so it is printed as a positive number. 6227020800 ignores the overflow; 479001600 is 12!; the negative option assumes every overflow produces a negative result.

More Pseudocode and Code Tracing questions

Exams that ask this topic