Multi-dimensional array initialization

Discussion in 'C Programming' started by masood.iqbal@lycos.com, Jan 23, 2005.

  1. Guest

    Hi,

    I have seen at least two ways to initialize multi-dimensional arrays in
    C. One of the ways is shown in a sample code snippet below. The other
    way does not make use of any intermediate braces. In other words, all
    the entries are listed under the same pair of enclosing braces. For
    example:

    char* mdTbl[3][5] = { "One", "Two", "Three", "Four","Five", "Six",
    "Seven",
    "Eight", "Nine", "Ten", "Eleven", "Twelve",
    "Thirteen",
    "Fourteen", "Fifteen" };

    Are the two approaches exactly identical, or is there any difference
    between them?

    Thanks,
    Masood
    /******************************************************
    ******************************************************/

    #include <stdio.h>


    char* mdTbl[3][5] = {
    {
    "One",
    "Two",
    "Three",
    "Four",
    "Five"
    },
    {
    "Six",
    "Seven",
    "Eight",
    "Nine",
    "Ten"
    },
    {
    "Eleven",
    "Twelve",
    "Thirteen",
    "Fourteen",
    "Fifteen"
    },
    };


    void
    print_array_element(int row, int column)
    {
    printf("%s\n", mdTbl[row][column]);
    }

    main()
    {
    print_array_element(2, 2);
    }
    , Jan 23, 2005
    #1
    1. Advertising

  2. CBFalconer Guest

    wrote:
    >
    > I have seen at least two ways to initialize multi-dimensional
    > arrays in C. One of the ways is shown in a sample code snippet
    > below. The other way does not make use of any intermediate braces.
    > In other words, all the entries are listed under the same pair of
    > enclosing braces. For example:


    Three copies of this malformed posting in less than 100 minutes! I
    suggest you find a newsreader, or a way of using google to make
    readable posts, with indentation and line lengths limited to 72
    (better 65) chars.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    CBFalconer, Jan 23, 2005
    #2
    1. Advertising

  3. Guest

    First of all my apologies for the multiple postings. It was certainly
    not intentional. Actually the google news-server kept giving me an
    error message to the following effect (paraphrasing here):

    Due to a temporary server error the message could not be posted.
    Kindly try again in 30 seconds.

    I actually waited for about a minute or so each time before reposting.
    I kept getting this error, and I kept retrying. It now appears to me
    that those were spurious error messages. I will be more careful in
    future (and just ignore this error message).

    It may a partial consolation that I have already removed the extra
    copies of my postings.
    , Jan 23, 2005
    #3
  4. CBFalconer Guest

    wrote:
    >

    .... snip ...
    >
    > It may a partial consolation that I have already removed the extra
    > copies of my postings.


    FYI you cannot remove your postings, no matter what your system
    tells you. They are distributed to many thousands of systems
    implementing usenet, most of which do not heed any cancel messages
    (due to misuse by imbeciles). Don't be misled by the idea that
    Google is the medium, it is actually a very small part of it. All
    those extra copies of your original are still residing on my
    system, and on my ISPs system, and many many other places.

    Meanwhile, listen to Eric Sosman.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    CBFalconer, Jan 23, 2005
    #4
    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. Venkat
    Replies:
    4
    Views:
    961
    Venkat
    Dec 5, 2003
  2. Grumble

    Multi-dimensional array initialization

    Grumble, Jan 26, 2004, in forum: C Programming
    Replies:
    4
    Views:
    689
    Jack Klein
    Jan 27, 2004
  3. Replies:
    3
    Views:
    469
  4. Replies:
    1
    Views:
    300
  5. Wirianto Djunaidi
    Replies:
    2
    Views:
    194
    Wirianto Djunaidi
    Apr 29, 2008
Loading...

Share This Page