Thread: please help me with this small question about array

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    254

    please help me with this small question about array

    Write an expression that accesses element 4 in subarray 2 in a two-dimensional array called twoD. The answer given in the book is: twoD[2][4].
    Is the answer correct? Shouldn't it be twoD[1][3] instead?

    Please let me know your opinion. Thanks.
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Element 4 does not necessarily mean the same thing as the fourth element. Element 4 is (or can be interpreted by convention to be) [4], while the fourth element is [3].

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    29
    The answer given in your boot is correct, for a declaration. but accessing that spot in the array would be your answer.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    254
    Write an expression that accesses element 4 in subarray 2 in a two-dimensional array called twoD. The answer given in the book is: twoD[2][4].
    Thanks, tabstop, Whyrusleeping.

    The keyword is "accesses". That confuses me. To access it I think my version is more correct. What do you say? Please have a second look. Thank you.
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    The trouble is . . .

    C++ programmers count like this: 0 1 2 3 4
    The rest of the world counts like this: 1 2 3 4 5

    When you are talking about programming I encourage you to count like a programmer. That's why the book isn't wrong.

    Also, I think it's a mistake to assume the question is wanting a declaration. A declaration is a statement, while the question asks for an expression, and declarations do not access anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Small problem with this array...
    By Merholtz in forum C Programming
    Replies: 7
    Last Post: 11-03-2008, 04:16 PM
  2. Small problem with printing elements of an array
    By DLR in forum C Programming
    Replies: 17
    Last Post: 03-09-2006, 06:57 PM
  3. Small array of strings prob
    By bstringer in forum C Programming
    Replies: 15
    Last Post: 08-04-2005, 06:27 PM
  4. A small question
    By suvesh in forum C Programming
    Replies: 14
    Last Post: 04-12-2004, 09:00 AM
  5. help with small program. array issue
    By InvariantLoop in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 12:26 PM