any can explain me the which a am going to calculate first of this
int α=1 double d=1.0
Code:
a = 5 + 5 * 2 % a--;
...
d + = 1.5 * 3 + (++d);
...
d - = 1.5 * 3 + d++;
Let me ask you, what did you expect the answer to be for any of these expressions?
The problem is that there is no answer. There is no guarantee when d++ or ++d will be executed in that block of code. There is something called a "sequence point" in C++, and I suggest you do a google search for that term.
Instead of code that looks like what you wrote, what's wrong with just doing things simple? Evaluate each step, one at a time instead of trying to erroneously cram everything into one statement.
i know the sequence but i can figure out these examples i run it in c++ and the results are different from those i made on the paper
that the reason i ask or help i anyone can explain how can calculate them
thanks
No you don't know the sequence, and neither does anyone else.
Again, there is no guarantee how C++ will calculate those lines. There is no "sequence" that is guaranteed to occur.
i run it in c++ and the results are different from those i made on the paper
So tell us, what did you do "on paper"? Did you just assume that "++d", "+=", "-=", and "d++" were supposed to always do things in a certain order if they appear in a single line of code? If you did assume this, then you're wrong.
Again, read the link I gave you. Simply put, if you have prefix, postfix, addition, subtraction on one line of code like that, then the behaviour of the program is undefined.
that the reason i ask or help i anyone can explain how can calculate them
No one can calculate them, since the sequence is ambiguous.
Paul already answered this. See the sequence point link. Those expressions do not have a guaranteed answer that will be the same on every C++ compiler you run it on.
Bookmarks