97 views

Please explain the solution, whats the actual logic in questions of Preprocessor codes?

recategorized | 97 views
+1
Just Run this two code.

#include <stdio.h>
#define fo(a) a*a

int main()
{
//printf("Hello World");
int a = 3;

printf("%d", foo(a +1));

return 0;
}

2.
#include <stdio.h>
int foo(int a)
{
return a * a;
}

int main()
{
//printf("Hello World");
int a = 3;

printf("%d", foo(a +1));

return 0;
}



+1
+1
While compilation itself , black(a) , black(a+1) and white(a) would be replaced with

a+a*a*a+1+a+1*a+1 - a - a*a

Now a is replaced with 3 ,

3 + 3 * 3 * 3 + 1 + 3 + 1 * 3 + 1 - 3 - 3 * 3 , And then execution based on precedence and associativity is done.
+1
Yes Program should eliminate braces during compilation. In that case precedence would get changed.
0
here - is before white ,it will not change whole expression of white ?