+ 2

what is the purpose of y=x++ i.e assigning x to y then increment it?

5th Feb 2017, 7:41 AM
Sopanaadevi.S
6 Respuestas
+ 14
Exactly, you got it right. So the value of y will be equal to default value of x but the value of x will increment afterwards. e.g var x = 1; var y = x++; results: y = 1 and x = 2 but, var x = 1; var y = ++x; results: y = 2 and x = 2 Here x is incremented before assigned to y
5th Feb 2017, 8:04 AM
Benneth Yankey
Benneth Yankey - avatar
+ 3
Any purpose you can imagine. The world is yours.
5th Feb 2017, 9:50 PM
funky
+ 1
its asign increment of x to y.
5th Feb 2017, 9:38 AM
pushpinder singh
pushpinder singh - avatar
+ 1
The purpose would be that you know you will need that variable to increment, or increase by 1, right after that portion of code is used. Consider a situation where you need to count how many times you do something, and then stop after you perform a task a certain number of times.
5th Feb 2017, 5:43 PM
Amber Nestor Gregory
Amber Nestor Gregory - avatar
0
Here us a video I made to help. C++ Increment and Decrement Explained Simply in 6 Minutes Order of Coding Operations https://youtu.be/GQQFCFWWnaA
6th Feb 2017, 2:33 PM
Amber Nestor Gregory
Amber Nestor Gregory - avatar
0
right
15th Feb 2017, 1:12 AM
JaydenSimmons