array question

This is a discussion on array question within the C Programming forums, part of the General Programming Boards category; I have seen a two dimensional array[x][y] to be used in the code like this : array[i] When it is ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    37

    array question

    I have seen a two dimensional array[x][y] to be used in the code like this : array[i]
    When it is used like this we mean that we only refer to the row and that the column is zero?
    Thank you.

  2. #2
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198
    Quote Originally Posted by skiabox View Post
    I have seen a two dimensional array[x][y] to be used in the code like this : array[i]
    When it is used like this we mean that we only refer to the row and that the column is zero?
    Thank you.
    Read this, and then check back if you need more help.

    Cprogramming.com C guide Arrays for Dummies

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    37
    I suppose that we can omit x or y if one of the two is zero.
    See this code that I get from a book I am reading :
    Code:
    for (i = 0; i < 9; i++)
        if (planets[i][0] == 'M')
           printf("%s begins with M\n", planets[i]);

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,712
    Quote Originally Posted by skiabox
    I suppose that we can omit x or y if one of the two is zero.
    If that were true, then this should have the exact same output:
    Code:
    for (i = 0; i < 9; i++)
        if (planets[i][0] == 'M')
           printf("%s begins with M\n", planets[i][0]);
    Likewise, this should mean the exact same thing:
    Code:
    for (i = 0; i < 9; i++)
        if (planets[i] == 'M')
           printf("%s begins with M\n", planets[i][0]);
    But neither is the case. You can run the former for yourself and verify that the output may be different, and then your compiler should complain about the latter, especially if you turn on warnings.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array Question
    By Alecroy in forum C++ Programming
    Replies: 4
    Last Post: 09-26-2010, 03:22 PM
  2. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 06:07 PM
  3. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 05:27 PM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

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