• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Array dimension

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why does this code is not legal ?

Does this mean array dimension are read from left to right ?(Associativity for [] operator).I don't find a reason or simply could understand the reason.Can somebody gimme me more example to explain
Thanks
-Badri
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Badri Narayanan:
Why does this code is not legal ?

Does this mean array dimension are read from left to right ?(Associativity for [] operator).I don't find a reason or simply could understand the reason.Can somebody gimme me more example to explain
Thanks
-Badri



Okay, this code:

int [][] testArray = new int[3][4];

Means to allocate an array of size 3, of int arrays. And in each element of this array, allocate an array of size 4, of ints.

This code:

int [][] testArray = new int[3][];

Means to allocate an array of size 3, of int arrays. But don't bother allocating each element of this array. Instead just set it to null.

So, if this code:

int [][] testArray = new int[][3];

was legal. What do you think the compiler should do? Should it allocate an unknown number of arrays of size 3, of ints. And assign it to elements of an array that won't be allocated?

Henry
[ December 14, 2006: Message edited by: Henry Wong ]
 
Badri Narayanan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Henry
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic