3D or 4D arrays

This is a discussion on 3D or 4D arrays within the C Programming forums, part of the General Programming Boards category; could someone explain to me the concept behind 3D or 4D arrays. how do i use them? tnx...

  1. #1
    Unregistered
    Guest

    Question 3D or 4D arrays

    could someone explain to me the concept behind 3D or 4D arrays. how do i use them?
    tnx

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    char one_d[10];
    char two_d[10][20];
    char three_d[10][20][30];

    Simple enough isn't it?

    The first you would access by
    one_d[x]

    Then
    two_d[x][y]

    And
    three_d[x][y][z];

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Declaring higher-dimensional arrays goes almost the same way as declaring one dimensional arrays.

    1D array of integers: int array [N];
    2D array of integers: int array [N][M];
    3D array of integers: int array [N][M][P];
    4D array of integers: int array [N][M][P][Q];
    etc.

    To use them is also almost the same. For a 4D array you could do something like:

    array [i][j][k][l] = value;

    An higher order array can be seen as a matrix. A 3D array is a 3D matrix. Imagine a cube which is split up in little cubes. Then the little cube on array [1][2][3] is the cube which is on the first row, second colom and three deep. For a 4D structure and higher it is harder to understand the concept.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    8
    think of arrays like this:

    square paper, where you can write only one character in each square. a strip of square paper with 10 squares, but only 1 square thick would be a 1d array.

    e.g

    char Example[10];

    now imagine you cut up the paper so that there were 10 rows of squares, and 10 columns. a 2d array,

    e.g

    char Example[10][10];

    for a 3d array, imagine you had 10 bits of paper, each 10 squares by 10 squares in size, sort of like a card filing system a library has.

    e.g

    char Example[10][10][10];

    4d array would be more complicated. imagine you had 10 card filing systems, each with 10 bits of paper, 10 rows and 10 columns, and imagine you had a filing cabinet, with 10 drawers, and you put a card filing system in each drawer.

    e.g

    char Example[10][10][10][10];

    and i'm gettin slightly bored of typin now. hope that made sense.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Allocating a number of large 3d arrays in C
    By Surrender in forum C Programming
    Replies: 22
    Last Post: 08-19-2008, 08:36 AM
  2. dynamically allocating 4D arrays
    By Marv in forum C Programming
    Replies: 15
    Last Post: 04-12-2007, 12:34 AM
  3. The deal with using 4d arrays :D
    By Shamino in forum C++ Programming
    Replies: 9
    Last Post: 11-05-2005, 01:28 AM
  4. Initialising 2D and 3D arrays
    By fry in forum C++ Programming
    Replies: 5
    Last Post: 08-01-2002, 04:34 AM
  5. 3d arrays
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2002, 09:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21