quick question about 2 dimensional array

This is a discussion on quick question about 2 dimensional array within the C Programming forums, part of the General Programming Boards category; lets say its something like array[4][4] it should have 4 columns and 4 rows If I want to access the ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    27

    quick question about 2 dimensional array

    lets say its something like array[4][4]

    it should have 4 columns and 4 rows

    If I want to access the particular location,

    say the 2nd row and 1st column, is it suppose to be array[2][1] or array[1][2]?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    Actually, indexes begin at 0 so 2nd row would be index 1 and 1st column would be index 0.

    But the order can really work whichever way you like it. However, the way C lays out the memory for an array is that the right-most index increases first. So the column is usually the 2nd index and the row is the first index.

    1 2 3 4 5
    6 7 8 9 0
    -- array[0][1] is 2.
    -- array[1][[3] is 9.

    Is that what you were looking for?
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    9
    The first number is the row and the second number is the columb. How everan array always starts from 0, so array [2][1] would point to the element in the third row and second columb. Hope this helps.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    27
    yes thank you very much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Array question
    By sniperwire in forum C Programming
    Replies: 3
    Last Post: 10-20-2008, 10:17 AM
  2. pointer/ array question..
    By transgalactic2 in forum C Programming
    Replies: 4
    Last Post: 10-14-2008, 06:06 PM
  3. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  4. two dimensional array
    By leisiminger in forum C Programming
    Replies: 12
    Last Post: 03-10-2008, 12:53 AM
  5. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 06:27 PM

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