![]() |
i want a complete explanation for this... please
pl.. explain a complete stack explanation for the below expression and say me the final value for j...
int i=16,j; j=i-- + i-- + --i + i--; printf("%d",j); :( |
Re: i want a complete explanation for this... please
This one has undefined behaviour, since it modifies the lvalue i without intervening sequence points.
See : http://en.wikipedia.org/wiki/Sequence_point. |
Re: i want a complete explanation for this... please
but this is giving the value of 'i' is 60... but for me when am working out 'i' is only 57 for me...
however this operation should have surely made use of STACK data structure......:smug: so only am asking the correct explanation with stack implementation...... plzzzz:) |
Re: i want a complete explanation for this... please
sorry , 'j' is giving me 60.... pl. explain with stack
|
Re: i want a complete explanation for this... please
Any explanation would be completely compiler specific. This expression gives undefined behaviour - that is the only possible answer. The explanation for that is what Saswat has already said: it modifies an lvalue more than once without an intervening sequence point. So to turn this into sensible code that has predictable results you must add sequence points, for example:
Code:
int i=16,j;Don't know why you want a stack-based explanation; the expression won't necessarily use a stack. In Visual Studio 2008 the result of: Code:
int i=16,j;Code:
int i=16,j;and the assembly code generated by the expression is: Code:
j=i-- + i-- + --i + i--; |
| All times are GMT +5.5. The time now is 02:22. |