Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: Two dimensi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 32 Topic 26121 of 26960
Post > Topic >>

Re: Two dimensional array Question

by Barry Schwarz <schwarzb@[EMAIL PROTECTED] > May 8, 2008 at 08:54 PM

On Thu, 8 May 2008 08:16:13 -0700 (PDT), mdh <mdeh@[EMAIL PROTECTED]
> wrote:

>I am still having a problem understanding K&RII on p 112. I have
>looked at the FAQs --which I am sure answer it in a way that I have
>missed, so here goes.
>A 2-dim array, (per K&R) is really a 1-dim array, each of whose
>elements is an array.

The C99 standard uses the term "multidinensional array" so K&R is
slightly out of date in this regard.

>Looking at the debugger I use, arr[2][13] is shown as an initial value
>of "2", but when expanded, there are 2 consecutive arrays of 13
>elements.

What do you mean by "2".  Is it an array of char arrays and the first
of such holds the string '2' '\0'?

>So, may I ask this?
>Is there anything special that marks the end of the first 13 elements
>from the beginning of the 2nd 13 elements? In other words, it seems to

No.  It is prohibited.  arr[1] must immediately follow arr[0] in
memory.

>me that this is nothing more than a 1-dim array, with the information
>about the structure of the array provided by the declaration?
>Hopefully this makes sense.

It is true that the 26 "basic elements" of arr will appear in memory
"linearly".  This has prompted many debates about whether a pointer to
arr[0][0] can be used with subscripts ranging from 0 to 25 to access
all 26.  What is not in dispute is that in a 1d array T x[N], x[0]
evaluates to an element of type T.  In your case, arr[0] evaluates to
an array of T.  To my mind, this is sufficient to say arr cannot be
considered a 1d array.

>
>The exercise associated with this, used the construct
>
> *p = arr[1 or 0 ] to point to either the "first" or "second" row of
>the array. Does the compiler "know" where to point to because it has
>been given this information by the declaration of "13" in arr[2][13].
>Hopefully this makes sense too!

Yes and yes.

>
>
>And lastly, K&R's description of "each of whose elements is an array"
>has never made sense to me. It may be that the answer to the above may
>clarify it.

arr[0] is an array 13 T.  arr[1] is an array of 13 T.  arr[2] does not
exist.  arr[i][j] is an object of type T as long as 0<=i<=1 and
0<=j<=12.  arr[i][j] is an element of arr[i] but not element of arr.
arr[i] is an element of arr and it is an array.


Remove del for email
 




 32 Posts in Topic:
Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-08 08:16:13 
Re: Two dimensional array Question
Joe Wright <joewwright  2008-05-08 19:15:37 
Re: Two dimensional array Question
"Default User"   2008-05-08 23:24:55 
Re: Two dimensional array Question
pete <pfiland@[EMAIL P  2008-05-08 21:03:36 
Re: Two dimensional array Question
"Default User"   2008-05-09 16:27:53 
Re: Two dimensional array Question
Ben Bacarisse <ben.use  2008-05-09 00:30:00 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-08 18:39:27 
Re: Two dimensional array Question
Barry Schwarz <schwarz  2008-05-08 20:54:09 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-09 06:18:51 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-09 20:35:22 
Re: Two dimensional array Question
pete <pfiland@[EMAIL P  2008-05-10 07:09:06 
Re: Two dimensional array Question
Ben Bacarisse <ben.use  2008-05-10 12:42:22 
Re: Two dimensional array Question
pete <pfiland@[EMAIL P  2008-05-10 08:43:58 
Re: Two dimensional array Question
Joe Wright <joewwright  2008-05-10 09:26:20 
Re: Two dimensional array Question
Ben Bacarisse <ben.use  2008-05-10 14:53:55 
Re: Two dimensional array Question
pete <pfiland@[EMAIL P  2008-05-10 12:25:49 
Re: Two dimensional array Question
Ben Bacarisse <ben.use  2008-05-10 17:12:46 
Re: Two dimensional array Question
Ben Bacarisse <ben.use  2008-05-11 01:17:26 
Re: Two dimensional array Question
Barry Schwarz <schwarz  2008-05-11 04:17:57 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-11 19:07:45 
Re: Two dimensional array Question
Richard Heathfield <rj  2008-05-12 03:16:04 
Re: Two dimensional array Question
Richard Heathfield <rj  2008-05-12 03:17:11 
Re: Two dimensional array Question
pete <pfiland@[EMAIL P  2008-05-12 07:18:50 
Re: Two dimensional array Question
"Default User"   2008-05-12 06:19:46 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-12 21:12:17 
Re: Two dimensional array Question
Richard Heathfield <rj  2008-05-13 04:48:22 
Re: Two dimensional array Question
Chris Torek <nospam@[E  2008-05-13 16:38:01 
Re: Two dimensional array Question
Richard Heathfield <rj  2008-05-13 16:53:43 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-12 21:13:55 
Re: Two dimensional array Question
pete <pfiland@[EMAIL P  2008-05-16 22:17:14 
Re: Two dimensional array Question
mdh <mdeh@[EMAIL PROTE  2008-05-12 22:26:08 
Re: Two dimensional array Question
Barry Schwarz <schwarz  2008-05-16 18:44:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Thu Jul 24 16:33:04 CDT 2008.