ProgrammingHardGATE CS · TCS NQT
What does this C program print? unsigned int x = 0xB5; printf("%x", x ^ (x >> 1));
- A. 1df
- B. ef
- C. ff
- D. 5a
Correct answer: B. ef
x = 1011 0101 and x >> 1 = 0101 1010. Their XOR is 1110 1111 = 0xef, the binary-to-Gray-code conversion. 0xff would be the OR, and 0x5a is the shifted value alone.
More C Programming questions
- What is the value of s after this loop? int i, s = 0; for (i = 0; i < 5; i++) { switch (i % 3) { case 0: s += 1; case 1: s += 10; break…
- What is printed? c #include <stdio.h> int main(void) { int a = 0, b = 1, c = 2; int r = (a++ && b++) || (c-- && a--); printf("%d %d %d…
- What is printed? Assume int occupies 4 bytes. c #include <stdio.h> int main(void) { int i = 5; sizet n = sizeof(i++) + sizeof(i = 100)…
- What is printed? Assume int is 32 bits and unsigned char is 8 bits. c #include <stdio.h> int main(void) { unsigned char c = 0x0F…
- What is printed? Assume int and unsigned int are 32 bits. c #include <stdio.h> int main(void) { int a = -1; unsigned int b = 1; printf("%d…
- What is the value printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned x = 0xB6D9 ^ 0x00FF; int n = 0…