0

Difference between all the codes and their outputs?

#define SQUARE(n) n * n main( ) { int j ; j = 64 / SQUARE ( 4 ) ; printf ( "j = %d", j ) ; } #define SQUARE(n) (n * n) main( ) { int j ; j = 64 / SQUARE ( 4 ) ; printf ( "j = %d", j ) ; } #define PRODUCT(x) ( x * x ) main( ) { int i = 3, j ; j = PRODUCT( i + 1 ) ; printf ( "\n%d", j ) ; }

17th Jul 2020, 4:47 AM
Sri pranavi Donapati
Sri pranavi Donapati - avatar
5 Answers
+ 1
Just do as directed :- 1) square(n) n*n 64/4*4 = 64 2)square(n) (n*n) 64/(4*4) = 4 3) product(x) (x*x) j = (3+1*3+1) = 3 + 3 + 1 = 7 4) product(x) (x)*(x) j = (3+1)*(3+1) = 16
17th Jul 2020, 4:52 AM
Arsenic
Arsenic - avatar
+ 4
macro is just a textual replacement . just replace the macro with what you have defined it to.
18th Jul 2020, 4:54 AM
Hima
Hima - avatar
+ 2
Sri pranavi Donapati see I have edited the response and thanks for pointing it out.
17th Jul 2020, 8:02 AM
Arsenic
Arsenic - avatar
0
Arsenic #define PRODUCT(x) ( x * x ) main( ) { int i = 3, j ; j = PRODUCT( i + 1 ) ; printf ( "\n%d", j ) ; } Output is 7 #define PRODUCT(x) ( x) *( x ) main( ) { int i = 3, j ; j = PRODUCT( i + 1 ) ; printf ( "\n%d", j ) ; } Output is 16 How?
17th Jul 2020, 5:37 AM
Sri pranavi Donapati
Sri pranavi Donapati - avatar
0
#define SQUARE(n) n * n main( ) { int j ; j = 64 / SQUARE ( 4 ) ; printf ( "j = %d", j ) ; }
3rd Apr 2021, 8:41 AM
sujan saren
sujan saren - avatar