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: <2439@utcsri.UUCP> Date: Mon, 31-Mar-86 14:49:52 EST Article-I.D.: utcsri.2439 Posted: Mon Mar 31 14:49:52 1986 Date-Received: Mon, 31-Mar-86 15:43:37 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: 55 Summary: why you would want one This is a repost - sorry if you've seen it, but it 'bounced', so I'm sending it again. ( How can news bounce? The stuff attached to the returned news ( presumably explaining the reason ) was greek to me... ) 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. -- "If you aren't making any mistakes, you aren't doing anything". ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg