If anyone can help me understand what is the benefit between writing Prefix to "change" the value of both 'x' and 'y' (1/2) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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;

28th Mar 2017, 8:51 AM
Carlos Almanza
Carlos Almanza - avatar
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”);
28th Mar 2017, 9:09 AM
Heng Jun Xi
Heng Jun Xi - avatar
+ 4
In more complex software you dont want to know what value your variables have so you just increment by using x++;
28th Mar 2017, 9:00 AM
T0nd3
+ 1
ok I see. Thank you
28th Mar 2017, 9:05 AM
Carlos Almanza
Carlos Almanza - avatar
+ 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.
28th Mar 2017, 4:37 PM
Mohammed Salman Khan
Mohammed Salman Khan - avatar