I need help with pointers and passing-by-refrence
Hello
I've been working on a program and I've encountered a little problem
Here is the simplest form of my problem
Code:
public static void main(String[] args) { int[] a = new int[]{1,2,3};
trial3(a);
}
private static void trial3(int[] i) {
int[] b = i;
b[1] = 0;
System.out.println(Arrays.toString(b)+ Arrays.toString(i));
}
I expect the result would be [1, 0, 3][1, 2, 3] but instead the real result is
[1, 0, 3][1, 0, 3]
I don't really know why this happen could someone please explain it to me and
Tell me a simple way to get the expected result.