2,304 views
1 votes
1 votes
What is the output of the following program?
# include <stdio.h>
# define MUL (a, b) a ∗ b
# define pow (a) a ∗ a
int main ( )
{
int a = 3;
int b = 2;
printf (“%”, MUL (MUL (a+1, b), pow (b + 1)));
return 0;
}

2 Answers

1 votes
1 votes
# include <stdio.h>
# define MUL (a, b) a ∗ b
# define pow (a) a ∗ a
int main ( )
{
int a = 3;
int b = 2;
printf (“%”, MUL (MUL (a+1, b), pow (b + 1)));
return 0;
}

Here we are using the #define directory, it goes through the entier program, search the macro template. whenever it finds, it replaces the macro template with appropriate macro expansion.

so expression in printf will be:

MUL ( MUL(a+1,b) , pow (b+1) )
MUL(a+1,b) *pow(b+1)
((a+1)*b)*(b+1)*(b+1)
3+1*2*2+1*2+1
3+2*2+2+1
3+4+2+1 = 10

* has higher priority than + and associativity is left to right.

Related questions

2 votes
2 votes
1 answer
1
rupamsardar asked Aug 30, 2023
494 views
#include <stdio.h int f(int x) { if(x%2==0) { return f(f(x-1)); } else return (x++); } int main() { printf("%d",f(12)); ret...
0 votes
0 votes
1 answer
2
SHWETAV SUMAN asked Oct 6, 2022
332 views
i have typed the following code but when i executed it the solution was not according to my expectation.unsigned short int y= -9; int iy=y; printf(“%d”,iy); solutio...
0 votes
0 votes
3 answers
3
ykrishnay asked May 30, 2022
1,067 views
int main(){extern int a = 20;printf("%d",a); }//why this gives error but followig code is not extern int a =20;int main(){printf("%d",a); } //why this happens that first ...
0 votes
0 votes
0 answers
4
ykrishnay asked May 20, 2022
386 views
What is stream in c programming ? as i read file io in c programming so thats where i read “stream” word so what stream means ? thank you