ProgrammingModerateTCS NQT · Wipro

What is printed?

What is printed?
int a = 2, b = 4;
printf("%d %d %d", a & b, a && b, a | b);
  1. A. 0 1 1
  2. B. 0 1 6
  3. C. 1 1 6
  4. D. 2 4 6

Correct answer: B. 0 1 6

2 = 010 and 4 = 100 share no bits, so a & b = 0, while a && b treats both as true and gives 1. a | b = 110 = 6. Confusing & with && is the trap in the first two.

More C Programming questions

Exams that ask this topic