Thread: Accessing array members

  1. #1
    Registered User
    Join Date
    May 2011

    Accessing array members


    are all the ways to access a member of a two-dimensional array listed below correct? I've tested the code and it seems to work properly.

    void do_something(int (*ap)[COLUMNS], int rows, int columns)
       int x, i, j;
       ... // assume we've assigned some values to i and j here
       x = (*(ap+i))[j]);
       x = *(&ap[0][0] + i * columns +j));
       x = *(*(ap+i) + j));
       x = ap[i][j];

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    You need COLUMNS and columns to represent the same number, for sure. But if that's true, then those should all get you to the same place, should you ever use any of them, which is between you and your conscience.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing Structure Members
    By anndruu12 in forum C Programming
    Replies: 5
    Last Post: 12-02-2010, 02:37 AM
  2. accessing enum members
    By stanlvw in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2008, 02:58 PM
  3. accessing Class members
    By fizisyen in forum C++ Programming
    Replies: 3
    Last Post: 01-07-2004, 06:18 PM
  4. Accessing structure members
    By foniks munkee in forum C Programming
    Replies: 18
    Last Post: 02-13-2002, 03:06 PM
  5. Accessing members of structures
    By Nutshell in forum C Programming
    Replies: 6
    Last Post: 02-03-2002, 12:10 PM