ProgrammingHardGATE CS · Campus placements
uint32_t fact(uint32_t n) { return n <= 1 ? 1 : n * fact(n - 1); } What does fact(13) return?
- A. 6227020800
- B. 1932053504
- C. 1932053505
- D. 0
Correct answer: B. 1932053504
13! is 6227020800, which wraps modulo 2^32 to 6227020800 - 4294967296 = 1932053504. The unsigned type makes this defined, but the value is not the true factorial.
More C Programming questions
- uint8t acc = 0; uint8t a[3] = {250, 3, 7}; for each element, acc += a[i]; What is acc after all three additions?
- int a[] = {3, 5, 6, 9}; int pre[5]; pre[0] = 0, and pre[i] = pre[i-1] ^ a[i-1] for i = 1..4. What is pre[4] ^ pre[1]?
- void f(int a) { sizet n = sizeof a / sizeof a[0]; ... } is called as f(arr) where int arr[4]. What is true about n?
- unsigned int n = 0u; int i = 0; if (i < n - 1) printf("loop"); What is printed?
- Is the C standard guaranteed to remove stack frames of tail-recursive calls, so that deep tail recursion cannot overflow the stack?
- int a[6] = {1, 2, 3, 4, 5, 6}; int p = a, q = a + 5; while (p < q) { int t = p; p++ = q; q-- = t; } What is a[1] afterwards?