Talk About Network

Google





Programming > C - C++ Learning > Re: order of ar...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 10 Topic 4079 of 4400
Post > Topic >>

Re: order of array subscripts

by vippstar@[EMAIL PROTECTED] Mar 25, 2008 at 11:49 AM

On Mar 25, 6:00 pm, Keith Thompson <ks...@[EMAIL PROTECTED]
> wrote:
> no...@[EMAIL PROTECTED]
 writes:
> > #include <stdio.h>
>
> > char uu[5][4];
>
> > main()
> > {
> > printf("%p %p %p\n",&uu[0][0],&uu[1][0],&uu[0][1]);
> > }
>
> > gives
>
> > C:\a>kwik
> > 0040C1F0 0040C1F4 0040C1F1
>
> > This suggests the rightmost array subscript iterates most quickly, so
> > uu is an array of 5 of array of 4 of char.
>
> > Is that understanding correct? Sorry for such a trivial question but I
> > think my understanding hitherto has been wrong.
>
> Yes, your understanding is correct.  And, as it turns out, this
> wasn't an arbitrary choice; C couldn't have defined it the other
> way without some major changes.  (<OT>Note that Fortran's rules
> are different.</OT>)
>
> The key point to understand here is that C doesn't really have
> multidimensional arrays as a distinct feature.  Your declaration
>
>     char uu[5][4];
>
> simply declares an array of arrays.  The behavior, including the
> fact that the rightmost subscript iterates most quickly, follows
> from that.
>
> Note that the standard does talk about multi-dimensional arrays.
> Strictly speaking, this is redundant; eveything the standard says
> about multi-dimensional arrays follows directly from the rules for
> one-dimensional arrays.  But in this case the redundancy is probably
> a good thing; C's array rules are subtle enough that extending them
> to the multi-dimensional case is not trivial.
>
> For more information, see section 6 (Arrays and pointers) of the
> comp.lang.c FAQ, <http://www.c-faq.com/>.
Hm.. now I'm confused too. is T arr[4][5] an array of 4 arrays of 5
Ts? or an array of 5 arrays of 4 Ts?
I believe it's the latter. (so, arr[0] is an array of 4 Ts)
Moreover, in the FAQ in question 6.17 there is an additional link
labeled "Yes, Virginia", but the link leads to a page with no content.
(it is not an external link)
Any idea what that is?

>
> Finally, some minor quibbles about your code, unrelated to your
> question:
<snip>
 




 10 Posts in Topic:
order of array subscripts
noway@[EMAIL PROTECTED]   2008-03-25 07:45:00 
Re: order of array subscripts
"Alf P. Steinbach&qu  2008-03-25 09:06:37 
Re: order of array subscripts
Keith Thompson <kst-u@  2008-03-25 09:00:23 
Re: order of array subscripts
vippstar@[EMAIL PROTECTED  2008-03-25 11:49:21 
Re: order of array subscripts
Andrey Tarasevich <and  2008-03-25 12:03:26 
Re: order of array subscripts
Eric Sosman <Eric.Sosm  2008-03-25 15:55:08 
Re: order of array subscripts
"Jim Langston"   2008-03-25 23:59:28 
Re: order of array subscripts
Keith Thompson <kst-u@  2008-03-26 00:43:57 
Re: order of array subscripts
Flash Gordon <spam@[EM  2008-03-26 07:38:23 
Re: order of array subscripts
pete <pfiland@[EMAIL P  2008-03-29 00:10:11 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 10:05:09 PST 2009.