+ 1
If anyone can help me understand what is the benefit between writing Prefix to "change" the value of both 'x' and 'y' (1/2)
(2/2) from say 25 to 26 and just writing a line like int x = 26, y=26;
4 Answers
+ 6
x++ or ++x is very useful in loops or counting things
example: (pseudo code)
1)int x = 0, counter = 0;
2)accept input from user into array
3)for(int i = 0; i < inputArray.length; i++){
if(inputArray[i] is valid){
counter++;
}
}
4)print(âthere isâ + counter + âof valid inputâ);
+ 4
In more complex software you dont want to know what value your variables have so you just increment by using x++;
+ 1
ok I see. Thank you
+ 1
-It will help you to increase the value of your variable..
-It is useful in loops
-it uses the same variable and increase/decrease its value.
-No new variable required to assign new value.