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>
int main(void) {
unsigned a = 65536u;
printf("%u", a * a);
}- A. 1
- B. 65536
- C. 0
- D. 4294967295
Correct answer: C. 0
65536 * 65536 = 2^32, and 32-bit unsigned arithmetic is defined modulo 2^32, so the product wraps to exactly 0. 4294967295 (UINT_MAX) assumes the value clamps at the maximum, which unsigned types never do.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { printf("%d", sizeof(char) - 2 > 0); }
- What is printed? c #include <stdio.h> int main(void) { int a[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4}; int best = a[0], cur = a[0]; for (int i…
- How many subarrays of {1, -1, 2, -2, 3} have sum zero? Compute with this program. c #include <stdio.h> int main(void) { int a[] = {1, -1…
- What is printed? c #include <stdio.h> int pc(unsigned n) { return n ? (int)(n & 1u) + pc(n >> 1) : 0; } int main(void) { printf("%d"…
- What is printed? c #include <stdio.h> int main(void) { printf("%d", (13 << 1) + 13); }
- How many numbers from 1 to 100 are multiples of 16? Compute with this program. c #include <stdio.h> int main(void) { int c = 0; for…