ProgrammingVery hardProduct company OA
Assume 32-bit unsigned int. What is printed?
Assume 32-bit unsigned int. What is printed?
unsigned int x = 65536;
printf("%u %u", x * x, x * (x - 1) / 2);- A. 0 2147450880
- B. 65536 2147450880
- C. 0 2147483648
- D. 0 0
Correct answer: A. 0 2147450880
Unsigned arithmetic is modulo 2^32. x * x = 2^32 wraps to 0. x * (x − 1) = 2^32 − 2^16 also wraps to 4294901760, which is below 2^32, and halving it gives 2147450880. The division happens after the wrap, so this is not the true n(n−1)/2.
More C Programming questions
- What is printed? c int i = 0; while (i++ < 5); printf("%d", i);
- What is printed? c #define LEVEL 2 #if LEVEL > 1 #define MSG "high" #elif LEVEL > 0 #define MSG "low" #endif #undef LEVEL #ifndef LEVEL…
- What is printed? c struct E { char name[8]; int age; }; struct E t[] = {{"Asha", 31}, {"Bilal", 27}, {"Chen", 45}, {"Dev", 22}}; struct E…
- What is printed? c int f(int a, int n) { if (n == 1) return a[0]; int m = f(a + 1, n - 1); return a[0] > m ? a[0] - m : m - a[0]; } int…
- What is printed? c printf("%.1f", 1 ? 3 : 2.5);
- What is printed? c int a = 0, b = 10; while (a < b) { a += 3; b -= 2; } printf("%d %d", a, b);