Explain the output of this code (when using continuous assignment and change of a variable to be used in the same statement)

public class Main{ public static void main(String[] args){ int a = 0; int[] b = new int[5]; int c = 3; b[a] = a = 3;//a is covered with 3, why the entry assigned with 3 is b[0] instead of b[3] System.err.println(b[0]); System.err.println(b[3]); System.err.println(b[a]); } } 

Output:

 3 0 0 

I suppose the reason may be fifth, like an intermediate variable buffer, but I'm still not quite sure how the operator b[a] = a = 3; works b[a] = a = 3; .

+5
source share

Source: https://habr.com/ru/post/1235587/


All Articles