Can someone please explain to me the difference between ++i and i++ when written as part of an expression (i.e. within loops and if statements) ? Thanks :)
Dani
3,971
The Queen of DaniWeb
Administrator
Featured Poster
Premium Member
Recommended Answers
Jump to PostOne thing that is good to remember is that ++i is returned by reference while i++ is returned by value.
Never heard that one before.:-O
Jump to PostHaahaa, good one Narue, But hell yeah that example will only give out errors.
Btw, balu116, please use the code tags. Posting source code like that is rude.
Jump to PostWhen did this become the noob gets it wrong thread?
It seems a magnet for 1-post people to chip in with their "interpretation" only to be corrected for getting some aspect of "side effect" or "sequence point" wrong.
Jump to PostxD but it can't be helped but corrected. Since others who are new here might get it wrong (which happens a lot). A good code writing practice is always appreciated.
Jump to PostTry reading the thread.
All 36 Replies
Tekmaven
258
Software Architect
Team Colleague
Chainsaw
12
Posting Pro in Training
TITAN
0
Newbie Poster
marceta
0
Posting Whiz in Training
meabed
37
Junior Poster
Team Colleague
Chainsaw
12
Posting Pro in Training
meabed
37
Junior Poster
Team Colleague
Dave Sinkula
2,398
long time no c
Team Colleague
tlee
1
Newbie Poster
let us c
0
Newbie Poster
kalinga
0
Newbie Poster
Dave Sinkula
2,398
long time no c
Team Colleague
FireNet
64
Posting Whiz in Training
nanosani
20
Technize.net addict
Team Colleague
XianBin
0
Newbie Poster
varun_sonkerr
0
Newbie Poster
varun_sonkerr
0
Newbie Poster
Wonder
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Salem
5,138
Posting Sage
prabhat padhy
0
Newbie Poster
shabinesh
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Gopala Krishnan
0
Newbie Poster
ChaseVoid
30
Junior Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
ChaseVoid
30
Junior Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
ChaseVoid
30
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.