About use index and pointer address array

Discussion in 'C Programming' started by Mronoal, Sep 26, 2011.

  1. Mronoal

    Mronoal

    Joined:
    Sep 18, 2011
    Messages:
    3
    //define this array
    char a[4][3][2] = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}},
    {{'g', 'h'}, {'i', 'j'}, {'k', 'l'}},
    {{'m', 'n'}, {'o', 'p'}, {'q', 'r'}},
    {{'s', 't'}, {'u', 'v'}, {'w', 'x'}}};

    //define pointer
    char (*pa)[2] = &a[1][0];
    char (*ppa)[3][2] = &a[1];

    /*-----------------------------------------------------
    i want to address 'r' by pa and ppa.
    help me ,thanks
    -------------------------------------------------------*/
     
    Mronoal, Sep 26, 2011
    #1
    1. Advertising

  2. Mronoal

    Mronoal

    Joined:
    Sep 18, 2011
    Messages:
    3
    i thank:
    char a[4][3][2] = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}},
    {{'g', 'h'}, {'i', 'j'}, {'k', 'l'}},
    {{'m', 'n'}, {'o', 'p'}, {'q', 'r'}},
    {{'s', 't'}, {'u', 'v'}, {'w', 'x'}}};
    char (*pa)[2] = &a[1][0];
    //typedef char t[2]
    //t *pa
    //a[1][0] ---> {'g','h'}
    //sizeof(a[1][0]) = 2
    //pa++ -->{'i', 'j'}
    //(pa+5)[1] --> 'r'
    char (*ppa)[3][2] = &a[1];
    //typedef char y[3][2]
    //y *ppa
    //a[1] --->{{'g', 'h'}, {'i', 'j'}, {'k', 'l'}}
    //sizeof(a[6]) = 6
    //ppa++ -->{{'m', 'n'}, {'o', 'p'}, {'q', 'r'}},
    //(ppa+1)[2][1]-->'r'

    BUT ,it's wrong
     
    Mronoal, Sep 26, 2011
    #2
    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. jimjim
    Replies:
    16
    Views:
    852
    Jordan Abel
    Mar 28, 2006
  2. Stanley Rice

    Address of array && address of pointer to array

    Stanley Rice, Sep 14, 2011, in forum: C Programming
    Replies:
    33
    Views:
    1,167
    Keith Thompson
    Sep 20, 2011
  3. subramanian100in@yahoo.com, India

    pointer to an array vs pointer to pointer

    subramanian100in@yahoo.com, India, Sep 20, 2011, in forum: C Programming
    Replies:
    5
    Views:
    465
    James Kuyper
    Sep 23, 2011
  4. Shawn W_
    Replies:
    5
    Views:
    302
    Aldric Giacomoni
    Sep 16, 2009
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    323
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page