+ 2

What does ++x mean and also what does y-- mean

pls like me in my profile

20th Feb 2017, 7:05 AM
josh
3 ответов
+ 4
Let's take a simple example, int x = 3;int y = ++x; In this both var 'x' and var 'y' become 4 as the compiler increases the value immediately. However, here.. int a = 4; int b = a--; var 'a' becomes 3 and 'b' becomes 4 because the compiler first assigns the value of var 'a' to var 'b' and then depreciates the value of var 'a' Hope this helps :)
20th Feb 2017, 11:42 AM
Chirag Bhansali
Chirag Bhansali - avatar
+ 3
"do first what you see first" int x= 3; int y = 0; y = x++ //first you see x so first assign x, then increment x here y=3 and x=4 but y = ++x //first you see ++ so first increment x then assign here y=4 and x=4
20th Feb 2017, 4:16 PM
Oma Falk
Oma Falk - avatar
+ 1
++x means "add 1 to x then evaluate x" y-- means "evaluate y then subtract 1 from y" They are similar but different. For example, int x = 5; System.out.println(++x); prints 6 because println evaluates x AFTER calcurating 5 + 1. In contrast, int x = 5; System.out.println(x++); prints 5 because println evaluates y BEFORE calculating 5 + 1.
20th Feb 2017, 7:52 AM
Twelfty
Twelfty - avatar