ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
#define INCREMENT(x) x = x + 1
int main(void) {
    int a = 5, b = 10;
    if (a > 0)
        INCREMENT(a);
    else
        INCREMENT(b);
    printf("%d %d", a, b);
}
  1. A. 6 10
  2. B. 5 11
  3. C. 6 11
  4. D. 5 10

Correct answer: A. 6 10

a > 0 is true, so INCREMENT(a) expands to `a = a + 1;`, making a=6; the else branch (which would have incremented b) is skipped entirely, so b remains 10.

More C Programming questions

Exams that ask this topic