← The Preprocessor: Macros & Conditional Compilation

Fix: Unparenthesized Macro

medium

This program computes (a + b) squared – but SQUARE’s definition is missing the parentheses from the lesson, and the call site makes it matter: SQUARE(a + b) passes an expression, not a bare variable.

Expand it by hand the way the compiler does, with a = 1, b = 2: SQUARE(a + b) becomes, by pure text substitution, a + b * a + b – which is 1 + 2 * 1 + 2 = 5, not the 9 that (1 + 2)^2 actually is. Fix the macro’s definition (not the call site, and not the main logic) so every occurrence of x in the body, and the body as a whole, is wrapped in parentheses.

Your solution

"Run" uses the sample stdin ("1 2"). "Submit" checks your code against all 4 test cases.

Test results

Submit your solution to run it against all test cases.

Reference solution