+ 5
Why the out put is 28 not 2?
4 Antworten
+ 4
the macro call square(4) will substituted by 4*4
so the expression becomes i = 28/4*4 . Since / and * has
equal priority the expression will be evaluated as (28/4)*4
i.e. 7*4 = 28
So output is 28
+ 5
If you want to have your intended result, define the macro with parantheses.
#define square(x) (x*x)
Even better, also put each x in parantheses. This way also input like square(1+3) yields the correct result
#define square(x) ((x)*(x))
See this summary for more insight:
https://code.sololearn.com/c80ech3GBNvc/?ref=app
+ 2
Matthias thank you so much ❤
+ 2
Thank you Preity ❤❤