ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned n = 37;
printf("%u", n ^ (n >> 1));
}- A. 54
- B. 18
- C. 55
- D. 37
Correct answer: C. 55
The Gray code of 37 is 37 XOR 18, which is 100101 XOR 010010 = 110111 = 55. Shifting left instead of right gives a different value.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int x = -8; printf("%d", x / 2 + x % 3); }
- What is printed? c #include <stdio.h> int calls = 0; int bs(const int a, int lo, int hi, int k) { calls++; if (lo > hi) return -1; int m =…
- What is printed? Assume short is 2 bytes, int is 4 bytes and both use natural alignment. c #include <stdio.h> struct S { char c; short s…
- How many steps does this Collatz loop take to reach 1 starting from 27? c #include <stdio.h> int main(void) { unsigned n = 27; int steps =…
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { return (const int )a - (const int )b; }…
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { int a = -1; unsigned b = 2; printf("%u"…