| Author |
Explain this code about Arrays
|
Rashid Mian
Ranch Hand
Joined: Feb 14, 2007
Posts: 31
|
|
Why above code gives comiplation error?
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
|
The line b[] = null doesn't make sense. You don't declare what b is, and you don't give a name to the array.
|
 |
Carol Enderlin
drifter
Ranch Hand
Joined: Oct 10, 2000
Posts: 1348
|
|
a and b aren't the same type, see the compilation error that I got a is int[] b is int[][]
|
 |
Anton Uwe
Ranch Hand
Joined: Jan 10, 2007
Posts: 122
|
|
|
b is a reference to a two-dimensional int array, a is a reference to a one-dimensional int array. You cannot assign a one-dim-array to a two-dim-array reference. So, "b=a" will raise a compile error.
|
 |
chintan ramavat
Ranch Hand
Joined: Sep 15, 2006
Posts: 134
|
|
You cannot do int i, j,k ; ===> ( int i, int j, int k) i think your array B is not making any sense like is it integer or any reference variable. int [] a ; int [] b ; would be valid with valuse ==> NULL
|
 |
Jesse Custer
Ranch Hand
Joined: Feb 07, 2007
Posts: 45
|
|
The code you wrote is the same as this: So now it's easier to see that a is a one-dime,sional array and b a 2-dimensional array. So Carol had it right. Grtz PS: In the K&B Book is stated that 'int[] a' is the same as 'int a[]'. This is not exactly correct. Although you will get the same result in this simple case, the difference is, that when you put the brackets before the name (next to the declared type), they will count for any variable you declare on that line. If you put the brackets after the name, they will only count for that specific variable. [ February 15, 2007: Message edited by: Jesse Custer ]
|
 |
 |
|
|
subject: Explain this code about Arrays
|
|
|