+ 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?

22nd Apr 2019, 10:19 AM
nihed‎
nihed‎ - avatar
2 Answers
+ 6
sqr(x) is x*x so sqr(3+1) is 3+1*3+1 you can do the math
22nd Apr 2019, 10:44 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 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/#
22nd Apr 2019, 10:46 AM
Илья Кузнецов
Илья Кузнецов - avatar