+ 1

Trouble with function like definitions

#include <stdio.h> #define func(x) x*x int main() { printf("%d",func(4-1)); return 0; } //Here I got output as -1 #include <stdio.h> #define func(x) (x)*(x) int main() { printf("%d",func(4-1)); return 0; } //Here I got output as 9 I thought both code were same but they are not. There is something I can't understand with these lines #define func(x) x*x #define func(x) (x)*(x) Can someone help me with this..

17th Apr 2020, 7:39 AM
சுவேகா
சுவேகா - avatar
1 Respuesta
+ 5
Yes , it works like this 1st one 4-1*4-1= -1 and 2nd one (4-1)*(4-1)=9 because of (x)*(x)
17th Apr 2020, 7:46 AM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar