freelanceprogrammers.org Forum Index » C
3-d arrays
Joined: 25 Jul 2003
Posts: 4
3-d arrays
hi can any one expln the below code in brief
main()
{
int a[2][3][2]={{ {2,4},{7,8},{3,4} }, { {2,2},{2,3},{3,4}}};
printf("%u %u %u %d
",a,*a, **a,***a);
printf("%u %u %u %d
",a+1,*a+1, **a+1 ,***a+1);
}
with regards,
ashwini
Win TVs, Bikes, DVD players and more!
Click on
Yahoo! India Promos
Joined: 19 Jul 2003
Posts: 29
3-d arrays
--- suganthi rams <ashvinistar@...> wrote:
> hi can any one expln the below code in brief
>
> main()
> {
> int a[2][3][2]={{ {2,4},{7,8},{3,4} }, {
> {2,2},{2,3},{3,4}}};
> printf("%u %u %u %d
",a,*a, **a,***a);
> printf("%u %u %u %d
",a+1,*a+1, **a+1 ,***a+1);
> }
Hmm...pointer arithmetic! Let`s dig:
a => &a[0]
*a => a[0] => &a[0][0]
**a => a[0][0] => &a[0][0][0]
***a => a[0][0][0] (value 2)
a+1 => &a[1]
*a+1 => a[0][1] => &a[0][1][0]
**a+1 => a[0][0][1] => &a[0][0][1]
***a+1 => (a[0][0][0]) + 1 (value 2+1=3)
Rewriting the assignment with comments:
int a[2][3][2]=
{ /* a */
{ /* a[0] */
{2,4}, /* a[0][0] */
{7,8}, /* a[0][1] */
{3,4} /* a[0][2] */
},
{ /* a[1] */
{2,2}, /* a[1][0] */
{2,3}, /* a[1][1] */
{3,4} /* a[1][2] */
}
};
Does that make some sense ? :-)
Regards,
Shantanu
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Joined: 25 Jul 2003
Posts: 5
3-d arrays
Hi suganthi,
Buy "POINTERS IN C" by Y.C. Kanetkar
you will understand the funda of double, triple and
more than triple pointers relation with array.
jateen
________________________________________________________________________
Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://uk.messenger.yahoo.com/
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







