ProgrammingHardProduct company OA

Assume 32-bit unsigned int. What is printed?

Assume 32-bit unsigned int. What is printed?
unsigned x = 0x27;            /* 10 0111 */
printf("%u %u", ~x & (x + 1), x | (x + 1));
  1. A. 1 39
  2. B. 16 47
  3. C. 8 47
  4. D. 8 40

Correct answer: C. 8 47

x + 1 = 10 1000 turns the trailing ones into zeros and the lowest 0 into 1. ~x & (x + 1) isolates that lowest zero bit of x: 1000 = 8. x | (x + 1) sets it: 10 1111 = 47. '40' is x + 1 itself.

More C Programming questions

Exams that ask this topic