ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
#define SQUARE(x) x * x
int main(void) {
    int a = 5;
    printf("%d", SQUARE(a + 1));
}
  1. A. 36
  2. B. 11
  3. C. a + 1 * a + 1
  4. D. Compile-time error: SQUARE needs parentheses around x

Correct answer: B. 11

Macros do pure textual substitution with no operator-precedence awareness: SQUARE(a + 1) expands to a + 1 * a + 1, which by normal precedence is a + (1*a) + 1 = 5 + 5 + 1 = 11, not (a+1)*(a+1)=36 as intended.

More C Programming questions

Exams that ask this topic