ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
unsigned char x = 0xF0;
printf("%d", (x ^ 0xFF) & 0x0F);- A. 0
- B. 15
- C. 240
- D. 9
Correct answer: B. 15
x^0xFF flips all 8 bits of x: 0xF0 -> 0x0F. ANDing with 0x0F keeps the low nibble (already 0x0F): result 0x0F = 15.
More C Programming questions
- What is printed? c int flags = 0; flags |= (1 << 2); flags |= (1 << 4); flags &= ~(1 << 2); printf("%d", flags);
- What is printed? c unsigned int x = 10; printf("%d", (x << 1) == (x 2)); printf(" %d", (x >> 1) == (x / 2));
- Assume 32-bit int, two's complement. What is printed? c int x = ~0; printf("%d %u", x, (unsigned int)x);
- 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);