Why is the return value not what I expected in this C program with macro? [duplicate]
问题 This question already has answers here : Strange behaviour of macros C/C++ (5 answers) Strange behavior of Macro-expansion (3 answers) Closed 6 years ago . When I run the following code, the return value is 11, but I was expecting it to return 25. Can someone explain this? #include<stdio.h> #define SQR(a) a*a int main() { int i=3; printf("%d",SQR(i+2)); return 1; } 回答1: Needs more parentheses. This: #define SQR(a) a*a expands to this: i+2*i+2 which is: 3+2*3+2 which is 11 because * has