About use index and pointer address array

Joined
Sep 18, 2011
Messages
3
Reaction score
0
//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
-------------------------------------------------------*/
 
Joined
Sep 18, 2011
Messages
3
Reaction score
0
//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
-------------------------------------------------------*/
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top