What is the point of using x++? Why would you not just use x+1, if they have the same result? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the point of using x++? Why would you not just use x+1, if they have the same result?

26th Oct 2018, 9:01 AM
Jason Emmanuel
Jason Emmanuel - avatar
3 Answers
+ 4
x++ is not equivalent to x + 1, but to x = x + 1. So x++ is shorter.
26th Oct 2018, 9:41 AM
Anna
Anna - avatar
0
because there's some distance. ++ is an one processor operation while += loads 1 at first and then performs addition.
26th Oct 2018, 9:34 AM
Sergey Ushakov
Sergey Ushakov - avatar
0
Mirrors the fact that incrementing has a special machine instruction.
26th Oct 2018, 1:17 PM
Vlad Serbu
Vlad Serbu - avatar