+ 1
why does the output is 7 instead of 16 ?????
#include <stdio.h> #define sqr(x) x*x int main() { printf("%d", sqr(3+1)); return 0; }
6 Réponses
+ 6
#define only replaces the variable name with the value. So,
sqr(3+1) = 3+1*3+1 = 3+3+1 = 7
To get 16 as output, you need to use parentheses. Like this:
#define sqr(x) (x)*(x)
+ 6
To get output 16 you may use
#define sqr(x) (x)*(x)
Then output will be
(3+1)*(3+1)
(4)*(4)
16
+ 3
Rajesh Dutta oo, sorry. My bad 😅
I wrote 9 instead of 7 by mistake 😁
+ 2
Martin Taylor Genuine Stalwart Sayed🇧🇩🇧🇩 This was in solo learn challenge, solo learn challenged me and the question was as it is like this, the correct answer says 7
+ 1
Genuine Stalwart thanks i finally understood that problem 👏👏
+ 1
Martin Taylor sololearn actually challenged me and this was the question as it is written so, i answered 16 but it showed correct answer is 7👍