ProgrammingHardInfosys · Wipro

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    printf("%d %u", 1 << 30 >> 29, (unsigned)-1 >> 30);
}
  1. A. 2 1
  2. B. 1 3
  3. C. 4 3
  4. D. 2 3

Correct answer: D. 2 3

Shifts associate left to right, so (1 << 30) >> 29 = 2. (unsigned)-1 is all ones, and shifting right by 30 leaves the two top bits, 3.

More C Programming questions

Exams that ask this topic