• 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

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.
 
Do not set lab on fire. Or this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic