• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Array confusion

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

This is from K&B book.



which of the following codes could be inserted at line 7, and still allow the code to compile? (choose four).

a) b2 [0][1] = b;
b) b [0][0] = b3;
c) b2 [1][1][0] = b [0][0];
d) b2 [1][2][0] = b;
e) b2 [0][1][0][0] = b [0][0];
f) b2 [0][1] = big;

I couldn't understand how to work it out the dimensions.
Can anyone please help.

Thanks.
 
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You just need to make sure that the reference types are the same in the LHS and RHS:


And to elaborate:

byte[][][][] b;
Now, b is a 4-dimensional byte array.
This means:
b[0] will be a 3-dimensional byte array, or a reference of type byte[][][]
b[0][0] will be a 2-dimensional byte array, or a reference of type byte[][]
b[0][0][0] will be a 1-dimensional byte array, or a reference of type byte[]
b[0][0][0][0] will be a reference of type byte (you can think of it as a 0-dimensional byte array)
 
a alph
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ruben for your very clear explanation.

Regards
alph
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic