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.

  1. i++ yields 0.

  2. then incremented 1.

  3. 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

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -