Thread: concepts on 3d array

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    141

    concepts on 3d array

    Could anyone please clear the following ideas regarding a 3d array to me?

    1. for an array, int arr[i][j][k], does arr++ mean anything?
    2. is cube (or a rectangular parallelepiped to be precise) a correct reperesentation of a 3d array? if so, how can i increment/decrement a particular cell data, say data at 1,2,2?

    Thanks,
    Angshu

  2. #2
    Rabble Rouser Slacker's Avatar
    Join Date
    Dec 2005
    Posts
    116
    >1. for an array, int arr[i][j][k], does arr++ mean anything?
    Nope, it's an error.

    >2. is cube (or a rectangular parallelepiped to be precise) a correct reperesentation of a 3d array?
    You can think of it that way if you want, but in memory a 3 dimensional array is just a one dimensional array with a little extra stuff to make indexing work like the cube representation.

    >how can i increment/decrement a particular cell data, say data at 1,2,2?
    Code:
    ++arr[1][2][2];

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    >1. for an array, int arr[i][j][k], does arr++ mean anything?
    Nope, it's an error.
    However, it does mean something on a pointer, such as int ***p. Just like with 1D and 2D arrays.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Rabble Rouser Slacker's Avatar
    Join Date
    Dec 2005
    Posts
    116
    >However, it does mean something on a pointer, such as int ***p.
    However, the question wasn't about a pointer, it was about an array.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by dwks
    However, it does mean something on a pointer, such as int ***p. Just like with 1D and 2D arrays.
    Also, since we're at it, you're a bit misleading here. This statement implies that incrementing a pointer has the same, or similar, effect as incrementing 1D and 2D arrays. Which of course is false, because you can't do: arrayname++, no matter how many dimensions it has.


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

  6. #6
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Another way it's misleading is dwks' statement implies that if you have an array:
    Code:
    int a[50][50][50];
    int b[50];
    And then you have:
    Code:
    int ***p = a;
    int *q = b;
    Then p++ will be useful in traversing the array, and it isn't. Though q++ is.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3D Array of Bool
    By cybernike in forum C++ Programming
    Replies: 37
    Last Post: 06-28-2007, 12:17 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 05:15 AM
  3. 3D array
    By GSLR in forum C Programming
    Replies: 2
    Last Post: 05-12-2002, 05:00 PM
  4. 3D Array
    By Alextrons in forum Windows Programming
    Replies: 4
    Last Post: 01-11-2002, 01:39 AM
  5. Dynamic 3D array allocation
    By Vulcan in forum C++ Programming
    Replies: 4
    Last Post: 11-21-2001, 02:51 AM
Website Security Test