242 views
1 votes
1 votes
I'm not able to understand how literal substitution will work while running this code?

#define CALC(X) (X*X)
int main() {
int a, b=5;
a = CALC(b+2);
printf("\n a= %d b=%d", a,b);
}

1 Answer

3 votes
3 votes
Output is a=17 and b=5;

first of all i will explain you that "The macro arguments are not evaluated before macro expansion. "

so when we pass the argument to this macro it will look like

b=5;

so a=CALC(5+2)// the macro calculate5+2*5+2

so a=17;

and the value of b will unchanged.

Related questions

0 votes
0 votes
1 answer
1
Debargha Mitra Roy asked Apr 16
89 views
#include <stdio.h int main() { int a[3] = {1, 3, 5, 7, 9, 11}; int *ptr = a[0]; ptr += sizeof(int); printf("%d", *ptr); return 0; }(Assume size of int to be $2$ bytes.)T...
0 votes
0 votes
2 answers
3
Debargha Mitra Roy asked Apr 10
131 views
What is the output of the below code?#include <stdio.h void main() { static int var = 5; printf("%d ", var ); if (var) main(); }a. 1 2 3 4 5b. 1c. 5 4 3 2 1d. Error
1 votes
1 votes
1 answer
4
SSR17 asked Feb 29
256 views
#include <stdio.h int main() { int i = -1; int x = (unsigned char)i; printf("%d", x); return 0; }output is 255 , but please explain how