+ 2

someone plz explain how this is resulting in 3

#include <stdio.h> #define square(x)(x*x) int main() { int x,y=1; x=square(y+1); printf("%d\n",x); return 0; }

4th Jun 2019, 11:34 AM
Aaditya Singh
Aaditya Singh - avatar
4 Answers
+ 4
square(y+1) becomes (y+1*y+1) And that becomes 1+1*1+1 which is 3. So y+1 isnt evaluated but just placed in the spots where x stands.
4th Jun 2019, 11:40 AM
Dragonxiv
Dragonxiv - avatar
+ 1
thanks
4th Jun 2019, 11:47 AM
Aaditya Singh
Aaditya Singh - avatar
8th Jun 2019, 6:16 PM
Shubham Tandale
Shubham Tandale - avatar
0
It goes like this 1. Substituting in the function. 2. Substituting the values. 3. evaluation. So according to the operator precedence first multiplication will be done and then addition.
5th Jun 2019, 4:40 AM
Talluri Saisumanth
Talluri Saisumanth - avatar