Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Explain this code about Arrays

 
Rashid Mian
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why above code gives comiplation error?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic