0

++ Confusion in java

++a , a++ what is difference

12th Feb 2025, 7:22 PM
Devashish kumar
Devashish kumar - avatar
3 odpowiedzi
+ 7
Devashish kumar , here a short description: => *pre-increment* operator: ++x is used to increment the value of variable `x` **before** using it in an expression. => *post-increment* operator: x++ is used to increment the value of variable `x` **after** executing the expression.
12th Feb 2025, 7:47 PM
Lothar
Lothar - avatar
+ 4
++a : pre-increment a++ : post-increment
12th Feb 2025, 7:39 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
+ 3
EXAMPLE - pre-increment x = 5; y = ++x; (increment x to 6, then assign 6 to y) EXAMPLE - post-increment a = 5; b = a++; (assign 5 to b, then increment a to 6) Both cases have the side-effect of incrementing and saving the variable. Just a question whether you access the value of the variable before or after the increment happens.
13th Feb 2025, 3:55 AM
Shardis Wolfe