#include<stdio.h>
#include<conio.h>
#define square(v) v*v
void main()
{
int p=3;
int s=square(++p);
printf("%d %d",s,p);
getch();
}
output 25 5 Why 16 4 is not coming as output? (Advance thanks)
A macro is basically a text copy and paste. Therefore your ++ is being duplicated.
The macro is being expanded as:
s = ++p * ++p;
That's the danger of macros. (in this case, it also invokes undefined behavior)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With