2 Respuestas
+ 3
Please avoid writing code into the post tags. Tags are search terms, and use of code in tags will ruin search engine performance and accuracy. https://code.sololearn.com/W3uiji9X28C1/?ref=app Apart from warming of unused variable, the unexpected result you see was due to the definition of macro function Macros are expanded before compilation begin. And the expansion is done by text replacement. So given the definition: #def square(x) x * x The expression square(4 + 1) Will be expanded into: 4 + 1 * 4 + 1 Where 4 + 1 represented by argument <x> fed to the macro. Operator precedence is the cause of the unexpected result. Here multiplication gets higher precedence over addition. So the expression could be evaluated as follows (multiplication is wrapped in parentheses) 4 + (1 * 4) + 1 4 + (4) + 1 9 To actually square a given argument <x>, we usually wrap the arguments by parentheses, to prevent the issue. #define square(x) (x) * (x) http://www.cplusplus.com/doc/tutorial/preprocessor/
1st Aug 2022, 6:26 AM
Ipang
+ 1
If you are talking about the warning, that's because you created a "x" variable and never used it.
1st Aug 2022, 5:37 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar