April 4th, 2013, 07:39 AM
x=++i + ++i + i++;
but not 35 why
April 4th, 2013, 09:15 AM
Do you know the difference between ++i (prefix) and i++ (postfix)?
If not, I suggest you look it up.
You can also try to split the line, e.g. that happens first, second etc.
April 4th, 2013, 10:08 AM
Yet another perennial crop of homework dealing with horrible examples of code that you must never write. <<sigh>>
Read up on sequence points (that's a link to a Wikipedia article).
Then read my explanation of a similar futile exercise, Evaluating (x + x * ++x).
Bottom line: if you really want to know why an expression was evaluated the way that it was, then read the assembly code that the compiler generated.
HINT: an expression like that can be handled differently by different compilers, so you cannot predict what answer you'll get. You'll have to read the assembly code generated by each compiler to figure it out.
Last edited by dwise1_aol; April 4th, 2013 at 10:11 AM.
April 4th, 2013, 03:52 PM