Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > About use index and pointer address array

Reply
Thread Tools

About use index and pointer address array

 
 
Mronoal Mronoal is offline
Junior Member
Join Date: Sep 2011
Posts: 3
 
      09-26-2011
//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
-------------------------------------------------------*/
 
Reply With Quote
 
 
 
 
Mronoal Mronoal is offline
Junior Member
Join Date: Sep 2011
Posts: 3
 
      09-26-2011
Quote:
Originally Posted by Mronoal View Post
//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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointer to an array vs pointer to pointer subramanian100in@yahoo.com, India C Programming 5 09-23-2011 10:28 AM
Address of array && address of pointer to array Stanley Rice C Programming 33 09-20-2011 12:47 AM
sorting index-15, index-9, index-110 "the human way"? Tomasz Chmielewski Perl Misc 4 03-04-2008 05:01 PM
Array of pointer and pointer of array erfan C Programming 6 01-28-2008 08:55 PM
passing the address of a pointer to a func that doesnt recieve a pointer-to-a-pointer jimjim C Programming 16 03-27-2006 11:03 PM



Advertisments