ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
#define SQUARE(x) x * x
int main() {
    int a = 5;
    printf("%d", SQUARE(a + 1));
}
  1. A. 6
  2. B. 11
  3. C. 36
  4. D. Compilation error: macro arguments must be parenthesized

Correct answer: B. 11

SQUARE(a+1) expands to the raw text a + 1 * a + 1, which by operator precedence (* before +) is a + (1*a) + 1 = 5 + 5 + 1 = 11, nowhere near the intended 6*6=36. Proper macro hygiene requires `#define SQUARE(x) ((x)*(x))`.

More C Programming questions

Exams that ask this topic