ProgrammingHardAccenture · Cognizant pattern

What is printed?

What is printed?
#define INCR(x) x++
int main() {
    int i = 5;
    int r = 2 * INCR(i);
    printf("%d %d", r, i);
}
  1. A. 12 6
  2. B. 10 6
  3. C. Compilation error: cannot use postfix ++ inside a macro argument this way
  4. D. 11 6

Correct answer: D. 11 6

INCR(i) expands textually to i++, so `2 * INCR(i)` becomes `2 * i++`. Postfix ++ yields i's ORIGINAL value (5) for the multiplication (2*5=11) and THEN increments i to 6 as a side effect.

More C Programming questions

Exams that ask this topic