ProgrammingHardTCS NQT · Wipro

What is printed?

What is printed?
#include <stdio.h>
#define SQ(x) x * x
int main(void) {
    int i = 3;
    printf("%d", SQ(i + 1));
}
  1. A. 16
  2. B. 9
  3. C. 10
  4. D. 7

Correct answer: D. 7

The macro substitutes the text, giving i + 1 * i + 1 = 3 + 3 + 1 = 7. Parenthesising the parameter as ((x) * (x)) gives 16.

More C Programming questions

Exams that ask this topic