+ 5
Why the output is 65 instead of 225 ?
#include <stdio.h> #define x 10+5 int main() { int a = x*x; printf("%d", a); return 0; }
4 Answers
+ 5
SIMRAN
#define x 10 + 5 //here x = 10 + 5
So x * x = 10 + 5 * 10 + 5 = 10 + 50 + 5 = 65
-------
#define x (10 + 5) //here x = (10 + 5)
So x * x = (10 + 5) * (10 + 5) = 225
-------
#define x (10) + (5) //here x = (10) + (5)
So x * x = (10) + (5) * (10) + (5) = 10 + 50 + 5 = 65
+ 5
10+5*10+5
Edit: you could instead #define x (10+5)
EDIT2: I think that define works before compilation, it does a (search replace) with the defined term definition.
eg if you đ#define x 5đ
it may just replace xray to 5ray. Let's test that, I will report back what I find!
EDIT3: I don't think macro #define replaces letters when they are part of a longer word.
hmmm....
https://code.sololearn.com/cl05IIc37s4E/?ref=app
+ 4
+ 3
x * x will be replaced with
10 + 5 * 10 + 5 which will be processed as
10 + ( 5 * 10 ) + 5 due to operator precedence (* priority is higher than +)
Hope it makes sense ...