ProgrammingHardHCL · Tech Mahindra pattern
Assume 32-bit int, two's complement. What is printed?
Assume 32-bit int, two's complement. What is printed?
int x = ~0;
printf("%d %u", x, (unsigned int)x);- A. 0 0
- B. -1 0
- C. 1 4294967295
- D. -1 4294967295
Correct answer: D. -1 4294967295
~0 flips every bit of 0, giving all-ones, which as a signed two's-complement int is -1. Reinterpreting that same bit pattern as unsigned gives the maximum unsigned value, 4294967295.
More C Programming questions
- Assume 32-bit int. What is printed? c int x = 13; int count = 0; while (x) { count += x & 1; x >>= 1; } printf("%d", count);
- Assume 32-bit int. What is printed? c int x = -5; printf("%d", x & 1);
- Assume 32-bit int, two's complement. What is printed? c int x = 7; int y = -7; printf("%d %d", x | y, x ^ y);
- What is printed? c int a = 0; for (int i = 0; i < 4; i++) { a |= (1 << i); } printf("%d", a);
- What is printed? c int x = 255; unsigned char y = (unsigned char)(x << 1); printf("%d", y);
- What is printed? c int x = 5, y = 9; int max = y ^ ((x ^ y) & -(x < y)); printf("%d", max);