ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
unsigned int x = 10;
printf("%d", (x << 1) == (x * 2));
printf(" %d", (x >> 1) == (x / 2));
  1. A. 1 0
  2. B. 1 1
  3. C. 0 1
  4. D. 0 0

Correct answer: B. 1 1

For a non-negative value with no overflow, left-shift by 1 is equivalent to multiplying by 2 (10<<1=20=10*2), and right-shift by 1 on an unsigned value is equivalent to integer division by 2 (10>>1=5=10/2). Both comparisons are true.

More C Programming questions

Exams that ask this topic