Thanks, leo
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Thanks, leo
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Thanks, leo
Originally posted by Maulin Vasavada:
so actually there is no meaning of having the second 3 in int a[][] = new int[3][3] right?
what does that second 3 do anyways?
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Originally posted by leo donahue:
I still don't get it. Look at the following:
On line # 3, what is happening? Do I have an array of 3 int arrays each with a length of 3?
On line # 5, what is happening? Why myArray[1]? What does this array index do for me? If I change it from 1 to 2, nothing is different about the print out.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Originally posted by Maulin Vasavada:
to generalize this...
the last index size doesn't matter.
if we had int[][][][][] a= new int[3][4][10][8][98];
then last [98] doesn't matter at all.
only first four index size will follow constraints.
ie. we can't write,
a[3][0][0][0] = new int[1];
as 3 will throw IndexOutOfBound...
try this...
here a[3][0][0][0]'s line throws exception but if u comment that, it would work...
regards
maulin
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Originally posted by Michael Morris:
Remember that myArray is a reference to a two dimensional array and that two dimensional arrays can be thought of as an array of arrays. So when you say myArray[1] you are now referring to the second int array. As you say, the print out is not affected by line #5 because arrays of primitives are initialized to 0. One might surmize that nothing happened on line # 5, but something did happen. On line # 3 the second int array was created and myArray[1] referred to it; on line # 5 you created a new array and assigned myArray[1] to that one. So what happened to the array from line #3? It became orphaned and now the garbage collector will eventually carry it off to the trash pile.
Try this:
[/QB]
Thanks, leo
Originally posted by leo donahue:
I am not following the pattern of what is happening when I re-initialize the myArray variable.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Hug your destiny! And hug this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|