ProgrammingHardProduct company OA

What is printed?

What is printed?
int i = 0, j = 0;
if (i++ & j++) ;
if (i++ && j++) ;
printf("%d %d", i, j);
  1. A. 1 1
  2. B. 2 2
  3. C. 2 1
  4. D. 2 0

Correct answer: B. 2 2

Bitwise & always evaluates both operands, so the first line makes i = 1 and j = 1. In the second, i++ yields 1, which is true, so && goes on to evaluate j++: i = 2, j = 2. '2 1' treats & as if it short-circuited.

More C Programming questions

Exams that ask this topic