#include<stdio.h>
# define SQ(r) r * r
main()
{
    int x = 2;
    int i = SQ(++x);
         printf("%d\n" ,i);
}

In the above code, how the result will be 16. If i give r * r * r, the result will be 80. how can it be possible. can anyone explain?

The text of a macro argument is used, not the value of the variable. So after expansion the statement is:

int i = ++x * ++x;

On top of being undefined behavior, that's probably not the logic you intended. Any expressions with side effects should be avoided as macro arguments:

++x;

int i = SQ(x);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.