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 ) ; }
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
+ 4
macro is just a textual replacement .
just replace the macro with what you have defined it to.
+ 2
Sri pranavi Donapati see I have edited the response and thanks for pointing it out.
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?
0
#define SQUARE(n) n * n
main( )
{
int j ;
j = 64 / SQUARE ( 4 ) ;
printf ( "j = %d", j ) ;
}