I've seen many posts about call by value and reference, but can barely find solutions for reference data types such as int[ ], or char[ ]. For example:
char b[] = new char[2];
b[0] = 'h';
b[1] = 'i';
char c[] = new char[2];
c = b; // copy by reference?
copy(c,b); // copy by value?
b[0] = 'b';
b[1] = 'y';
System.out.print(b[0]);
System.out.println(b[1]);
System.out.print(c[0]);
System.out.println(c[1]);
public static void copy(char[] dst, char[] src) {
dst[0] = src[0];
dst[1] = src[1];
}
c = b; changes value because c gets b's address?
copy(c,b); can't change value because it is copy by value? But I thought char[ ] is one of reference data types which can change the value. For example int[ ] is reference data type so it can change the value like below:
int[] d = new int[1];
d[0] = 1;
function(d);
System.out.println(d[0]);
public static void function(int[] a) {
a[0] = 4;
}
Does anyone know about this?