Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Multi-dimensional array

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a simple doubt in multi-dimensional arrays. Please help in understanding the below code:

Given:
12. float f[ ][ ][ ] = new float[3][][];
13. float f0 = 1.0f;
14. float[ ][ ] farray = new float[1][1];

Which is valid?
A. f[0] = f0;
B. f[0] = farray;
C. f[0] = farray[0];
D. f[0] = farray[0][0];
Answer: B

i thought answer as A.

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


B chicce is correct because f[0] refers to a 2dimensional floating array and since farray is 2dimensional so f[0] = farray.

to help you to understand better let me make a change in array f..

now:
f[0] refers to 2dimensional float array.
f[0][0] refers to a 1dimensional float array and
f[0][0][0] stores a floating point value !!

hope this explanantion helps!!
[ July 25, 2007: Message edited by: Priyam Srivastava ]
 
Seema Sharma
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Priyam,
Can you explain me this with small example. I still have a doubt how:

f[0] refers to 2dimensional float array.
f[0][0] refers to a 1dimensional float array and
f[0][0][0] stores a floating point value


Regards,
Seema
 
Priyam Srivastava
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


can you tell exactly what your confusion is, as it might help you to give a better example..
thanks!
[ July 25, 2007: Message edited by: Priyam Srivastava ]
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Seema,

I've prepared a short example:


Cheers,
Robert
[ July 25, 2007: Message edited by: Robert Horvath ]
 
Seema Sharma
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Priyam and Robert for your explanations.
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic