Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Can some one answer this question (http://www.go4expert.com/forums/answer-question-t9900/)

avinash_reddy 10Apr2008 10:30

Can some one answer this question
 
hi friends can some one answer this question plz

int x=2;
int r= x-- * ++x + ++x;
printf("x= %d, r= %d", x, r);

and also for

r= ++x + ++x * --x;

and

r= ++x + ++x * x--;

can some explain how these expressions are eveluated

shabbir 10Apr2008 19:34

Re: Can some one answer this question
 
The answer can change from compilers to compilers and so see what is the output in your compiler and just try justifying it.

tarek issa 10Apr2008 19:43

Re: Can some one answer this question
 
i understood ur question.
there is a trick in doing x++ and ++x, for example:
if doing this:
++x*2 first x multiplyese by 2, and then it (x) increases by 1.
if doing this:
x++*2 first x increases by 1, and then the multiply will be done.

technosavvy 11Apr2008 16:34

Re: Can some one answer this question
 
trying googling sequence point and u will understand why it is an undefined behaviour


All times are GMT +5.5. The time now is 00:05.