Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   #define Unexpected Output (http://www.go4expert.com/forums/define-unexpected-output-t8597/)

shyam_oec 1Feb2008 21:12

#define Unexpected Output
 
#define pro(X) (X*X)
main()
{

int i=3,j,k;
j=pro(i++);
k=pro(++i);
printf("\n%d %d",j,k);
getch();
}

output is 9 49
can any one explain why we get second output as 49. i guessed second output to be 25 before running the above code.

oogabooga 1Feb2008 21:56

Re: #define Unexpected Output
 
This is a combination of what is generally considered to be a bad macro (argument referenced twice) and the undefined behavior discussed here starting at post number 5.


All times are GMT +5.5. The time now is 09:29.