Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang.c Subject: Address of array Message-ID: <2419@utcsri.UUCP> Date: Fri, 28-Mar-86 15:53:15 EST Article-I.D.: utcsri.2419 Posted: Fri Mar 28 15:53:15 1986 Date-Received: Fri, 28-Mar-86 16:25:06 EST References: <313@hadron.UUCP> <2377@utcsri.UUCP> <530@umcp-cs.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 52 Summary: Why you would want one In article <530@umcp-cs.UUCP> chris@umcp-cs.UUCP (Chris Torek) writes: >In article <2377@utcsri.UUCP> greg@utcsri.UUCP (Gregory Smith) writes: > >> char (*char_ar_ptr)[80]; >> ...[ a pointer to array of char ] >> >> char line[80]; /* this is what I want to point it at */ > >> char_ar_ptr = &line; /* this should work ... */ > >Debatable. ( obviously! ) > >This works, and is probably even what you `really' mean: > > #define N 2 /* e.g. */ > char lines[N][80]; > > char_ar_ptr = lines; > >If you only have one line, why do you need to point at a set of >lines? Good point ... I actually hadn't thought of it exactly that way. Two answers come to mind, though: (1) Because it is there. :-) (2) Suppose the array 'lines' is actually more than two: char lines[10][80]; Suppose I want to point char_ar_ptr at lines[i] ( a perfectly reasonable thing to want to do ): This is allowed: char_ar_ptr = lines + i; /* let's really confuse those novices! >:-) */ This isn't: char_ar_ptr = &lines[i]; /* pointer to the ith array */ So &a[b] is not equivalent to a+b here. What a shame. I like using &a[b] in general, and ALWAYS use it when 'a' is an array as opposed to a pointer. Too bad I can't... especially when there's no good reason for not being able to. -- "Everything under the sun is tune, but the sun is eclipsed by the moon" - PF ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg