See code (Java):
public static int[] array(){
int[]arr={0,1};
changeArr(arr);
return arr;
}
public static void changeArr(int[]arr){
arr[0]=100;
arr[1]=101;
}
then I print the element in arr [], I find that arr [0] turns into 100, and arr [1] goes into 101, and I know that right, since the changeArr () method changes the values.
However
public static int m(){
int m=0;
changeM(m);
return m;
}
public static void changeM(int m){
m=100;
}
why does the value of m not change? If I print m, m is still 0, it doesn't change to 100, why? why the elements in the array can change, but the primitive type m does not change?
source
share