+ 1

how that work?

#include <stdio.h> #define x 10+5 int main() { int a=x*x; printf("%d",a); return 0; }

3rd Aug 2021, 11:24 AM
Devil Sniper
Devil Sniper - avatar
2 ответов
+ 6
#define is preprocessor directive, and compiler replace all x in your code on 10+5, so your code for compiler will look like: int a = 10 + 5 * 10 + 5; And a = 65, because exist priority of operations #define don't count, it replace
3rd Aug 2021, 11:40 AM
Roma Butaku
Roma Butaku - avatar
+ 3
The expression a = x * x; Will be replaced with a = 10 + 5 * 10 + 5; Considering multiplication operation has higher priority over addition, multiplication of 5 * 10 is processed first, then the result (50) will be added by 10 to the left, and 5 to the right.
3rd Aug 2021, 11:44 AM
Ipang