ProgrammingModerateTCS NQT · Accenture

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned x = 6;
    printf("%u", (x >> 1) ^ x);
}
  1. A. 5
  2. B. 3
  3. C. 4
  4. D. 6

Correct answer: A. 5

The Gray code of 6 is 6 XOR 3 = 110 XOR 011 = 101, which is 5.

More C Programming questions

Exams that ask this topic