ProgrammingHardProduct company OA

Assume 32-bit unsigned int. What is printed?

Assume 32-bit unsigned int. What is printed?
unsigned int u = 1u << 31;
printf("%u %u", u >> 31, (u >> 30) | (u >> 28 & 1));
  1. A. 1 2
  2. B. 1 10
  3. C. 1 3
  4. D. 0 2

Correct answer: A. 1 2

u has only bit 31 set, so u >> 31 = 1 and u >> 30 = 2. In u >> 28 & 1 the shift binds first: (u >> 28) & 1 = 8 & 1 = 0, so the OR leaves 2. '10' forgets the & 1 (2 | 8).

More C Programming questions

Exams that ask this topic