Possible Duplicate:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)
What problems might the following macro bring to the application?
I wrote a sample application with macro expansion for implementing it in my iOS (Objective C code).
It is something like:
#define SQUARE(x) ( x * x )
main( )
{
int i = 3, j, k ;
j = SQUARE( i++ ) ;
k = SQUARE( ++i ) ;
printf ( "\nValue of i++ = %d\nValue of ++i = %d", j, k ) ;
}
The output was:
Value of i++ = 9
Value of ++i = 49
Expected output was:
Value of i++ = 9
Value of ++i = 25
I'm surprised by this result. I'm little bit confused with this macro expansion.
Why did it happen? Please help me to find the reason.