ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
unsigned int u = -16;     /* 32-bit unsigned int */
printf("%d %u %d", 1 << 4, u >> 28, -16 / 4);
  1. A. 16 -1 -4
  2. B. 16 15 -4
  3. C. 16 15 -5
  4. D. 4 15 -4

Correct answer: B. 16 15 -4

1 << 4 = 16. −16 stored in an unsigned int is 0xFFFFFFF0; shifting right by 28 leaves the top four bits, 0xF = 15 (logical shift for unsigned). −16 / 4 is exactly −4. Right-shifting a negative signed value would be implementation-defined, which is why u is unsigned.

More C Programming questions

Exams that ask this topic