+ 2
what is the purpose of y=x++ i.e assigning x to y then increment it?
6 odpowiedzi
+ 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
+ 3
Any purpose you can imagine. The world is yours.
+ 1
its asign increment of x to y.
+ 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.
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
0
right