ProgrammingHardProduct company OA · TCS NQT

What is printed?

What is printed?
#define INC(x) x++; x++
int a = 0, b = 0;
if (a > 5) INC(b);
printf("%d", b);
  1. A. 2
  2. B. 0
  3. C. 1
  4. D. Compilation error

Correct answer: C. 1

After expansion the code is `if (a > 5) b++; b++;`. The if controls only the first statement, so the second b++ always runs and b becomes 1. This is exactly the bug the do { } while (0) idiom prevents.

More C Programming questions

Exams that ask this topic