ProgrammingHardGATE CS · Competitive coding (CP)

What is printed?

What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint32_t a = 0xFFFFFFFDu, b = 5u, c = 4u, d = 0xFFFFFFFFu, e = 0u, f = 7u;
    printf("%u %u %u", (a ^ b) >> 31, (c ^ d) >> 31, (e ^ f) >> 31);
}
  1. A. 1 0 0
  2. B. 0 1 0
  3. C. 1 1 1
  4. D. 1 1 0

Correct answer: D. 1 1 0

Two values differ in their top bit exactly when the XOR has its top bit set. 0xFFFFFFFD ^ 5 and 4 ^ 0xFFFFFFFF both have the top bit set, while 0 ^ 7 does not.

More C Programming questions

Exams that ask this topic