• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

multidimensional arrrays

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int[] a, b[];
In the above code snippet, a is a single dimensional array & b is 2 dimensional array....Am I right?

Pls correct me if I'm wrong.
 
author
Posts: 23928
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
Correct. "a" is an array of ints. "b" is an array of arrays of ints.

Henry
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an excerpt from my notes...

When declaring an Array, the identifier can appear anywhere amid the pairs of brackets denoting the dimension (but not enclosed within brackets). For example...

String s[][];
String []s[];
String [][]s;

When an Array of a given type and dimension is declared, any subsequent identifiers on that line can add dimensions -- provided that the brackets indicating the additional dimensions come after the associated identifier.

int[][]a, b, c[];

In the above declaration, a and b are both declared as 2-dimensional Arrays, while c adds a dimension to become a 3-dimensional Array.

Note, however, that in the declaration below, d is a 2-dimensional Array (an Object), while e remains a primitive int.

int d[][], e;

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
cote

Note, however, that in the declaration below, d is a 2-dimensional Array (an Object), while e remains a primitive int.

int d[][], e;


Why in the above declaration e is not a 2-d array ??
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what if int[][]d, e; was there then d and e both are 2-D arrays???
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by anshi kohli:
what if int[][]d, e; was there then d and e both are 2-D arrays???

Yes.
reply
    Bookmark Topic Watch Topic
  • New Topic