+ 1
why the output is 7??
her's the code : #include <stdio.h> #define sqr(x) x*x int main() { printf ("%d",sqr(3+1)); return 0; } the output was 7,why it's not 16?
2 Answers
+ 6
sqr(x) is x*x
so sqr(3+1) is 3+1*3+1
you can do the math
+ 3
Because your sqr(x) x*x translates to 3+1*3+1. To get 16 you have to put x in parenthises like: #define sqr(x) (x)*(x), which will be translated to (3+1)*(3+1).
See: https://code.sololearn.com/cgDbTQlct1DD/#