TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

If i = 0, why is i += i++ 0?

8 pointsby ivoflipseover 12 years ago

6 comments

Claudusover 12 years ago
The answer, from the same site:<p><a href="http://stackoverflow.com/questions/24853/what-is-the-difference-between-i-and-i" rel="nofollow">http://stackoverflow.com/questions/24853/what-is-the-differe...</a><p>"<i>++i will increment the value of i, and then return the incremented value.</i>"<p>"<i>i++ will increment the value of i, but return the pre-incremented value.</i>"
评论 #4820031 未加载
snover 12 years ago
Using gcc or g++ I get "1" not "0" for that expression, as I would intuitively expect. But this is undefined behavior in c/c++: tmp.c: In function ‘main’: tmp.c:3:5: warning: operation on ‘i’ may be undefined [-Wsequence-point]
评论 #4820539 未加载
yen223over 12 years ago
Why did they close the question?
评论 #4821053 未加载
lsiebertover 12 years ago
This is for c# not c or c++, fyi
krobover 12 years ago
this is correct. i = 0; i+=i++;<p>(0) + (0)++ = 0 next time around (1) + (1)++ = 2
评论 #4821102 未加载
crpatinoover 12 years ago
undefined behavior, isn't it? might as well be 42.