in the meantime, I have tested it with an online tool … the result i got (22) seems to be right (second test with an other tool)
Well seems like your compiler is really forgiving^^
We learnd to code with zero tolerance and that bit of code would most like have raised several syntax errors and warnings^^
Also @Heurazio I did it in my head too now (was too lazy before) and calculated 22^^ So it is most likely the right result^^ or rather the correct one since it doesn’t seem to be his age xD
As I said, this example is quite compiler dependent.
@KuroKuma
Yes this is definitely a good example for a bad programming style, but it did what it was supposed to do (keep you guessing for a while )
Now it would be interesting where your compiler looses an increment. Because I would consider that a bug (even if it only occurs while programming with bad style^^)
Stil a nice brain exercise^^
It seems that you got an extra increment.
int main()
{
int y = 4;
int x;
++y+y++;
y is 6 now.
So first x=6+6 is calculated then y is incremented 2 times. (this is probably where the compiler differ)
printf("%d", ++x+y++);
x gets incremented (13 now) then it is added with y (8 now) and 21 gets displayed. Only after that y gets incremented.
But it´s no big deal, in a few weeks your result will be correct
Sorry for getting off-topic @Saint_X
Now I feel stupid xD yea I did the first post increment before the addition was completed and assigned to x >_> so x was 13 for me which doesn’t make any sense now that I think about it again^^
21 should be correct.
I think it could be that some compilers do it as follows: read value, increment value, do with value whatever it was read for in the first place. (in this example 6 + 7 instead of 6 + 6)
I can’t explain it otherwise^^
Still bad that some compilers do it wrong regardless of what the bug is.
strange… what compiler version do you use ?
Why should it be incremented twice ?
x = y+++y++;
is a non-atomic instruction … furthermore the binding of ++ is higher than the of + and last but not least it’s from left to right … (EDIT: It’s from right to left for + operator … but this does not change the outcome)
so it’s 6 (keep 7 in mind) + 7 (keep 8 in mind) = 13
last but not least it’s 14 (++x) + 8 (keep 9 in mind) = 22 … this seems totaly logical to me … both online tools (one is gcc 4.3) get the same result …
yep … Visual Studio is raising like 100 error’s when i try to run this (joking … )
Well, are you a god?
Sooooo… I was right with my first thought?^^ God that ++ makes things more complicated rather than making them easier.
TIL that ++ binds stronger than + so thanks for that^^
And yea I didn’t even think about it if it could be atomic or not xD
I like that, how this simple thread got totally out of topic with personal informatic discussions
Well, and of daemons or gods xD
It IS called off-topic for a reason xD
Y’all ruined my punchline!
…
i hate it XD
so now i have changed it to general, I had not thought that it is so full spamming …
Well you consider it spamming, I consider it going with the flow^^
But I know that it can be quite annoying if people drift away from the topic you had in mind at the start.
I would say let’s go back to the (off) topoc this thread was originally about^^
That is kinda what happens when you make such a swallow topic, everything would have gone much better if you had done an “Introduce yourself” topic, cause then people would have something more to write than:
18 (10 sign limit)
Yea swallow topics tend to fly away^^ (sorry had to be^^)
I will keep this form just because of your pun
I’m 22 years old, a very creative and imaginative person who likes a lot modeling, texturing and all work relationated with that.
I moved it back to off topic where it belongs.
Modeling as in
BTW. STILL 18. IM PUTTING IN MY AGE SO ITS FINE