ProgrammingModerate

printf("%d", (1 << 4) | (1 << 2)); What is printed?

  1. A. 20
  2. B. 16
  3. C. 4
  4. D. 24

Correct answer: A. 20

1 << 4 is 16 (10000) and 1 << 2 is 4 (00100); OR combines the non-overlapping bits into 10100 = 20. 16 drops the second term, and 24 uses 1 << 3 by mistake.

More C Programming questions

Exams that ask this topic