Two problems, both from missing parentheses, because macros are textual substitution. First, the body isn't parenthesized, so SQUARE(a) + b is fine but the macro's result can bind wrong in a larger expression. Second and worse, the argument isn't parenthesized: SQUARE(1 + 2) expands to 1 + 2 * 1 + 2, which evaluates as 1 + (2*1) + 2 = 5, not 9. The fix is to wrap each argument and the whole body: #define SQUARE(x) ((x) * (x)), giving ((1 + 2) * (1 + 2)) = 9. The deeper lesson is that the preprocessor pastes text without understanding operator precedence, so you must defend every macro with parentheses, or, better, use a static inline function that the compiler type-checks and evaluates correctly.
C Programming · Interview question
What's wrong with #define SQUARE(x) x * x?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
The Preprocessor
Text substitution before the compiler ever runs: object and function macros, header guards, conditional compilation, and why a naive MAX macro evaluates its argument twice.