i've had this question ever since i learned two dimensional arrays... and i hope someone can clarify things for me..
here's what i know
int[] x= new int[2];
this one dimensional array has two elements.
int[][] y=new int[2][3];
this two dimensional array has six elements right? (2 x 3 = 6)
but when i look into the way a two dimensional array is actually made,
first a reference type variable named y that can store memory addresses of a two-dimensional array is made in the stack.
then an object with two elements that can store one dimensional memory addresses is made in the heap.
- then another 2 one-dimensional arrays are made, each consisting 3 elements that can store int type values. and the memory addresses of these two one dimensional arrays are assigned to the two elements that were made earlier inside the object.
- then this object's memory address is assigned to the y variable that is in the stack.
now the problem i have is, only two elements are made inside that object in the beginning right? so doesn't that mean that the two dimensional array has two elements. and the two one-d arrays have 3 elements each?
all of these questions bugs me because y.length = 2 and y[0].length =3
please correct me if i am wrong and hope someone could help me. thanks