arrayCopy confusion
in
Programming Questions
•
2 years ago
Hi,
When I run the following code:
- float[][] X={{1,2,3},{4,5,6}}; //initialize X
- float[][] Y=new float[2][3]; //initialize Y
- arrayCopy(X,Y); //copy X to Y
- println(Y[0][0]); //print the first value in Y
- X[0][0]=Y[1][0]; //change the first value in X
- println(Y[0][0]); //print the first value in Y (again).
The first print command gives a 1, and the second gives a 4. So a value in Y has changed! I'm racking my brains trying to figure out how this can be. Any help would be much appreciated.
thanks, :-)
~Patch
1