ProgrammingHardTCS NQT · Infosys
uint64_t f = 1; for (uint64_t i = 1; i <= 21; i++) f *= i; What is f after the loop?
- A. 51090942171709440000
- B. 0
- C. 14197454024290336768
- D. 2432902008176640000
Correct answer: C. 14197454024290336768
The exact 21! is 51090942171709440000, which exceeds 2^64. Unsigned multiplication keeps the value modulo 2^64, giving 14197454024290336768. Stopping at 20! would give 2432902008176640000.
More C Programming questions
- How many subsets of {1, 2, 3, 4, 5} have a bitwise XOR of their elements equal to 0? Count the empty set.
- How many integers i with 1 <= i <= 100 have bit 3 (value 8) set in their binary form?
- uint32t x = 0x12345678u; the 32-bit left rotation by 8 bits, written as (x << 8) | (x >> 24), gives what value?
- What is the Hamming distance between a = 0b1011 and b = 0b0110, that is the number of bit positions where they differ?
- A uint32t x = 37 is rounded up to a power of two by this code: x--; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; x++…
- int a = -7, m = 5; What is ((a % m) + m) % m, the non-negative residue of a modulo m?