my code is:-
#include<stdio.h>
#include<conio.h>
#define sq(x) x*x*x
void main()
{
printf("Cube is : %d.",sq(6+5));
getch();
}
The output is:-
Cube is : 71.
now please help me out that why the output is 71 and not 1331…
thank you in advance.
You need parentheses around the argument.
Without the parentheses, the expression will expand to:
Which you can see why it would evaluate to
71.A safer solution would be to use an inline function instead. But, you would need to define a different one for each type. It might also be more clear to rename the macro.