How can I increment/decrement a multidemensional array without a loop?

Discussion in 'C++' started by Hendrix, Jun 29, 2003.

  1. Hendrix

    Hendrix Guest

    Hi, I would like to pick four elements from a multidemensional array
    and use the content of those elements. I want to do this without all
    the subscript calls required for individual access, just want this for
    speed. I know you can increment regular arrays via ++array or array++
    etc. etc. but how do you do it with multidemensional arrays? lets say
    I have array[x][y] and I need to access array[x+1][y+1] how can I do
    this without the subscripts? The x and y count is at 64 by the way.

    Thanks for any help.
     
    Hendrix, Jun 29, 2003
    #1
    1. Advertising

  2. "Hendrix" <> wrote in message
    news:...
    > Hi, I would like to pick four elements from a multidemensional array
    > and use the content of those elements. I want to do this without all
    > the subscript calls required for individual access, just want this for
    > speed. I know you can increment regular arrays via ++array or array++
    > etc. etc. but how do you do it with multidemensional arrays? lets say
    > I have array[x][y] and I need to access array[x+1][y+1] how can I do
    > this without the subscripts? The x and y count is at 64 by the way.


    It's as simple as:
    itemPtr += (rowLen+1);
    Or in the case you mention:
    itemPtr += 65;
    Assuming that itemPtr points within: Item dataArray[64][64]; and
    is in-range.

    Note that, when starting to fiddle with item address calculations
    in multi-dimensional arrays, I would recommend using a 1-dimensional
    array and doing all offset calculations manually. While IIRC the
    sub-arrays are supposed to be contiguous, using a consistent
    approach should be preferred IMO.

    hth,
    --
    Ivan Vecerina, Dr. med. <> http://www.post1.com/~ivec
    Soft Dev Manger, XiTact <> http://www.xitact.com
    Brainbench MVP for C++ <> http://www.brainbench.com
     
    Ivan Vecerina, Jun 29, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Turney
    Replies:
    11
    Views:
    4,286
    dibeas
    Nov 13, 2006
  2. John
    Replies:
    4
    Views:
    1,143
    Vladimir Marko
    May 17, 2005
  3. Ian Pilcher

    Increment, decrement, overflow, and underflow

    Ian Pilcher, Jan 20, 2005, in forum: C Programming
    Replies:
    5
    Views:
    586
    CBFalconer
    Jan 21, 2005
  4. lovecreatesbeauty
    Replies:
    8
    Views:
    1,665
    Old Wolf
    Sep 12, 2005
  5. Angel Tsankov
    Replies:
    8
    Views:
    476
    Ian Collins
    Feb 27, 2006
Loading...

Share This Page