[Solved] Rules for using ‘define’ [closed]


#define P1(x) x+x
#define P2(x) 2*P1(x)
int a=P1(1)?1:0;
int b=P2(a)&a;

after code substitution it will look like this:

int a=1+1?1:0;
int b=2*a+a&a;

Since 1+1 is not false, a will be 1, so:

int b=2*1+1&1 

for clearness, I will write it with parenthesis (see operator precedence):

int b=((2*1)+1)&1

which is equivalent to:

int b=3&1 

which is equivalent to:

int b=0b0011 & 0b0001 

which is equivalent to:

int b=0b0001 

which means b=1

solved Rules for using ‘define’ [closed]