+ 4

What is the difference between a ++5 and a 5++

16th Jun 2019, 7:54 PM
Isloe Zuber
Isloe Zuber - avatar
6 Réponses
+ 9
5 is an integer literal and cannot be incremented. Both ++5 and 5++ are wrong. Increment can only be performed on variables (x++, ++i etc.)
16th Jun 2019, 8:02 PM
Anna
Anna - avatar
+ 6
You can think that ++x and x++ performs 2 tasks: increments x by 1 and returns x's value. The difference between ++x and x++ is on: which of these 2 tasks is performed first. In ++x: x first get's incremented by 1, then it returns x's value. In x++: first x's value get's returned, then x is incremented by 1.
16th Jun 2019, 8:18 PM
Seb TheS
Seb TheS - avatar
+ 6
https://code.sololearn.com/cCCCG1UQ2fss/?ref=app This will Clear your doubts :).
16th Jun 2019, 8:42 PM
Anon Fox
Anon Fox - avatar
+ 2
Isloe Zuber see Seb TheS above answer
29th Jun 2019, 8:22 AM
Sandray Fostin
Sandray Fostin - avatar
+ 1
so what is the difference between ++x or x++?
16th Jun 2019, 8:09 PM
Isloe Zuber
Isloe Zuber - avatar
+ 1
1.Priority of x++ is less than all of operator c have . 2. Priority of ++x is greater than all of operator c have. 3. But... they work in same way.
20th Jul 2019, 11:37 AM
Suraj Patra
Suraj Patra - avatar