Formal Argument for int Array[x][y]?

Discussion in 'C Programming' started by erktek@gmail.com, Nov 18, 2005.

  1. Guest

    Hi!
    It is clear that when we try to pass a one dimentional array to a
    function
    we use int* such as


    void display(int *LocalAarray)
    {
    ......
    }

    int main(void)
    {
    int MainArray[3] = {1, 2, 3};

    display(MainArray);
    return 0;
    }
    name of the array is automaticly casted to (int*)
    but what is the case I want to use two dimensional array ?
    int main(void)
    {
    int MainArray[2][3] = {{1, 2, 3},
    {4,5,6}};

    display(MainArray);

    return 0;
    }

    what should be the formal parameter of display function?
    void display(int** Local Array) ? <-- Is it true?
    , Nov 18, 2005
    #1
    1. Advertising

  2. Skarmander Guest

    wrote:
    > Hi!
    > It is clear that when we try to pass a one dimentional array to a
    > function
    > we use int* such as
    >
    >
    > void display(int *LocalAarray)
    > {
    > ......
    > }
    >
    > int main(void)
    > {
    > int MainArray[3] = {1, 2, 3};
    >
    > display(MainArray);
    > return 0;
    > }
    > name of the array is automaticly casted to (int*)
    > but what is the case I want to use two dimensional array ?
    > int main(void)
    > {
    > int MainArray[2][3] = {{1, 2, 3},
    > {4,5,6}};
    >
    > display(MainArray);
    >
    > return 0;
    > }
    >
    > what should be the formal parameter of display function?
    > void display(int** Local Array) ? <-- Is it true?
    >

    That's a good question, which is why the answer is in the FAQ:
    http://www.eskimo.com/~scs/C-faq/q6.18.html

    Read the rest of it while you're there, it's good stuff.

    S.
    Skarmander, Nov 18, 2005
    #2
    1. Advertising

  3. haroon Guest

    haroon, Nov 18, 2005
    #3
  4. pete Guest

    wrote:
    >
    > Hi!
    > It is clear that when we try to pass a one dimentional array to a
    > function
    > we use int* such as
    >
    > void display(int *LocalAarray)
    > {
    > ......
    > }
    >
    > int main(void)
    > {
    > int MainArray[3] = {1, 2, 3};
    >
    > display(MainArray);
    > return 0;
    > }
    > name of the array is automaticly casted


    "converted" is a more better word to use than "casted", there.

    > to (int*)
    > but what is the case I want to use two dimensional array ?
    > int main(void)
    > {
    > int MainArray[2][3] = {{1, 2, 3},
    > {4,5,6}};
    >
    > display(MainArray);
    >
    > return 0;
    > }
    >
    > what should be the formal parameter of display function?
    > void display(int** Local Array) ? <-- Is it true?


    void display(int (*Local_Array)[3]);

    --
    pete
    pete, Nov 18, 2005
    #4
  5. Skarmander Guest

    haroon wrote:
    > Skarmander wrote:
    > [snip]
    >
    >
    >>That's a good question, which is why the answer is in the FAQ:
    >>http://www.eskimo.com/~scs/C-faq/q6.18.html

    >
    >
    > who is responsible for this FAQ and what is the frequency of update?
    >

    Steve Summit () is the one responsible, and the last
    update was on July 3, 2004 (this is the version posted monthly to the ng
    and available through anonymous FTP at rtfm.mit.edu). Search Usenet
    archives like Google's for the skinny.

    S.
    Skarmander, Nov 18, 2005
    #5
  6. Eric Sosman Guest

    haroon wrote:
    > Skarmander wrote:
    > [snip]
    >
    >
    >>That's a good question, which is why the answer is in the FAQ:
    >>http://www.eskimo.com/~scs/C-faq/q6.18.html

    >
    >
    > who is responsible for this FAQ and what is the frequency of update?


    Read the FAQ.

    True, it only answers one of your questions completely.
    But it gives a pretty good hint about the other, and I don't
    think you deserve a more complete answer until you've given
    some tiny indication that you're willing to expend two or
    three of your own mouse clicks in pursuit of knowledge. You've
    been served a URL on a silver platter; can you eat it yourself,
    or do you need servants to lift each morsel to your lips, or
    maybe even chew it for you?

    --
    Eric Sosman
    lid
    Eric Sosman, Nov 18, 2005
    #6
  7. Skarmander <> writes:
    > haroon wrote:
    >> Skarmander wrote:
    >> [snip]
    >>
    >>>That's a good question, which is why the answer is in the FAQ:
    >>>http://www.eskimo.com/~scs/C-faq/q6.18.html

    >> who is responsible for this FAQ and what is the frequency of update?
    >>

    > Steve Summit () is the one responsible, and the last
    > update was on July 3, 2004 (this is the version posted monthly to the
    > ng and available through anonymous FTP at rtfm.mit.edu). Search Usenet
    > archives like Google's for the skinny.


    A more up-to-date version, in gzipped text format, is at
    <ftp://ftp.eskimo.com/u/s/scs/C-faq/faq.gz>. The HTML pages don't
    appear to have been updated since 1995.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Nov 18, 2005
    #7
    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. Gil
    Replies:
    6
    Views:
    4,550
  2. Schnoffos
    Replies:
    2
    Views:
    1,212
    Martien Verbruggen
    Jun 27, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,634
    Old Wolf
    Jan 20, 2004
  4. Replies:
    0
    Views:
    346
  5. Alain Spineux
    Replies:
    6
    Views:
    630
    Eric Sosman
    May 17, 2011
Loading...

Share This Page