+ 1
Why is output of this code is 65 and why ain't it is 225?
#include <stdio.h> #define x 10+5 int main() { int a=x*x; printf("%d",a); return 0; }
3 ответов
+ 2
Because #define is just an expression, when the compiler encounters "x" it doesn't calculate the operation, it simply replaces x with 10+5.
So you will have:
int a = 10+5*10+5;
// a = 10+50+5 = 65
If you want the result to be 225 you should write the code like this:
int a = (x)*(x);
+ 2
Simply it will be calculate ---
10+5*10+5 so answer is 65
+ 1
Rising Abhinav , because the calculation is the following => 10+5*10+5 => 65. If you place brackets and change the line define x (10 + 5), I think you'll get the desired result.