Post increment in Java -
this question has answer here:
in code segment,
[1]int i=0; [2]i = i++; [3]system.out.println(i);
in line 2, executed expression first (which assigned 0 i) , should increment value 1.
in system.out.println(i)
, getting answer 0 instead of 1.can explain reason this?
i++ not yield variable, value.
i++ yields 0.
then incremented 1.
then 0 assigned i.
summary: precedence of operators maybe not expected. or @ least might've misunderstood actual increment of happening. it's normal show people use of i++ can split 2 lines line after doing incrementation - that's not correct. happens before assignment operator.
Comments
Post a Comment