Multiple choice

What would be the output of the following?

#define SQR(x) x*x main() { int a,b=3; a=SQR(b+2); printf(“%d”,a); }

  1. 25

  2. 11

  3. Error

  4. Garbage Value

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The macro SQR(x) expands to x*x. When called as SQR(b+2), it becomes b+2*b+2, NOT (b+2)*(b+2). Due to operator precedence, multiplication happens first: 3+2*3+2 = 3+6+2 = 11. The macro lacks parentheses around x and around the entire expression, causing this common pitfall.