ngn@lemy.loldeleted by creator to Programmer Humor@lemmy.mlEnglish · 2 years agogot himlemy.lolimagemessage-square53linkfedilinkarrow-up125arrow-down12
arrow-up123arrow-down1imagegot himlemy.lolngn@lemy.loldeleted by creator to Programmer Humor@lemmy.mlEnglish · 2 years agomessage-square53linkfedilink
minus-squarenelson@lemmy.worldlinkfedilinkarrow-up0·2 years agop = 1 x = ++p // x = 2 // p = 2 p = 1 x = p++ // x = 1 // p = 2 ++p will increase the value and return the new value p++ will increase the value and return the old value I think p = p + 1 is the same as p++ and not as ++p. No?
minus-squareSpaceNoodle@lemmy.worldlinkfedilinkarrow-up0·2 years ago(p += 1) resolves to the value of p after the incrementation, as does ( p = p + 1).
minus-squarenelson@lemmy.worldlinkfedilinkarrow-up0·2 years agoYes. p++ == p+= 1 == p = p + 1 are all the same if you use it in an assignment. ++p is different if you use it in an assignment. If it’s in its own line it won’t make much difference. That’s the point I was trying to make.
minus-squareSpaceNoodle@lemmy.worldlinkfedilinkarrow-up1·2 years agoNo. ++p returns incremented p. p += 1 returns incremented p. p = p + 1 returns incremented p. p++ returns p before it is incremented.
p = 1 x = ++p // x = 2 // p = 2p = 1 x = p++ // x = 1 // p = 2++pwill increase the value and return the new valuep++will increase the value and return the old valueI think
p = p + 1is the same asp++and not as++p. No?(p += 1) resolves to the value of p after the incrementation, as does ( p = p + 1).
Yes.
p++==p+= 1==p = p + 1are all the same if you use it in an assignment.++pis different if you use it in an assignment. If it’s in its own line it won’t make much difference.That’s the point I was trying to make.
No.
++p returns incremented p.
p += 1 returns incremented p.
p = p + 1 returns incremented p.
p++ returns p before it is incremented.