- 1
Tell me how this works please
I am reading java docs and it states: int i = 10; int n = i ++%5; it then askes what are the values after this code is executed. I say well i=10 so 10 and n =i ++ is 11 then %5 answer is 2.. Nope, they say its 11 and 0. How?
2 Answers
+ 6
i = 10
n = i ++ % 5 //i++ is postfix increment
//original i value will be used first (10)
// and added later after used it
//10%5 = 0
//n = 0
//now the value of i will increased by 1
//therefore i = 11
0
Thanks heng!