How old are You?

in the meantime, I have tested it with an online tool … the result i got (22) seems to be right :smiley: (second test with an other tool)

1 Like

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 :smile:)

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 :smile:


Sorry for getting off-topic @Saint_X :sweat_smile:

1 Like

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.

1 Like

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 … :smiley: )

1 Like

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 :smiley:
Well, and of daemons or gods xD

1 Like

It IS called off-topic for a reason xD

Y’all ruined my punchline!

1 Like

:smiling_imp:

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^^

1 Like

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)

4 Likes

Yea swallow topics tend to fly away^^ (sorry had to be^^)

2 Likes

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.

1 Like

I moved it back to off topic where it belongs.

3 Likes

Modeling as in

BTW. STILL 18. IM PUTTING IN MY AGE SO ITS FINE

2 Likes