In Java for example:
int x[] = {1,2,3,4};
int y[] = x;
y[0] = 100;
System.out.println(x[0]);
System.out.println(y[0]);
Output:
100
100
How can I change the values of int y without changing values of int x?
You are pointing to same array location hence updating one will update the second.
Use clone() method to create copy of the array.
int x[] = {1,2,3,4};
int y[] = x.clone();
y[0] = 100;
System.out.println(x[0]);
System.out.println(y[0]);
Output :
1
100
int x[], that syntax is discouraged (and IMHO a historic mistake). The general convention is to useint[] x, as that is far more clear and readable to most Java programmers.