ProgrammingVery hardTCS NQT · Infosys
What is printed? Assume unsigned int is 32 bits.
What is printed? Assume unsigned int is 32 bits.
#include <stdio.h>
unsigned f(unsigned n) {
unsigned r = 1;
for (unsigned i = 2; i <= n; i++) r *= i;
return r;
}
int main(void) {
printf("%u", f(13));
}- A. 1932053503
- B. 1932053504
- C. 6227020800
- D. 1932053505
Correct answer: B. 1932053504
13! = 6227020800 exceeds 2^32 = 4294967296, and unsigned multiplication keeps the value modulo 2^32, giving 1932053504. The value 6227020800 cannot be stored in unsigned int.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { unsigned a[] = {5, 3}; printf("%u", a[0] - a[1] 2); }
- What is printed? c #include <stdio.h> int main(void) { int p = (int[]){1, 2, 3}; printf("%d", p[1] p[2]); }
- What is printed? c #include <stdio.h> int main(void) { printf("%u", 1u << 31 >> 30); }
- What is printed? c #include <stdio.h> int main(void) { char w[] = {"ab", "cd", "ef"}; char p = w + 2; printf("%c%c", (p)[0], p[-1][1]); }
- What is printed? c #include <stdio.h> int main(void) { unsigned v = 0x01020304u, total = 0; for (int i = 0; i < 4; i++) { unsigned b = (v…
- What is printed? Compute the XOR of all integers from 1 to 1000 with this program. c #include <stdio.h> int main(void) { unsigned x = 0…