Thread: 3 D arrays

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    1

    3 D arrays

    Could someone explain how 3d arrays work? The question I have is :

    For 1 d arrays we refer to an element as A[i]
    for 2d , A[i][j].
    But when we use 3 d arrays how do we find out what A[i][j][k] refers to, that is, what the value stored in it is?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    int array[ XSIZE ];
    int twodee[ YSIZE ][ XSIZE ];
    int threedee[ ZSIZE ][ YSIZE ][ XSIZE ];
    1) You have an array of something. 0 through size - 1.
    2) You have an array of those arrays. 0 through thissize - 1.
    3) You have an array of those arrays. 0 through thisothersize - 1.

    And so on. It's easy to keep track of it if you just read it from right to left.

    An array, XSIZE big...
    An array of those, YSIZE big...
    An array of those, ZSIZE big...


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  4. Building B-Tree from Arrays
    By 0rion in forum C Programming
    Replies: 1
    Last Post: 04-09-2005, 02:34 AM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM