Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!sri-spam!ames!ucbcad!ucbvax!cartan!brahms!ballou From: ballou@brahms (Kenneth R. Ballou) Newsgroups: comp.lang.c Subject: Re: pointers to arrays Message-ID: <371@cartan.Berkeley.EDU> Date: Wed, 19-Nov-86 03:50:21 EST Article-I.D.: cartan.371 Posted: Wed Nov 19 03:50:21 1986 Date-Received: Wed, 19-Nov-86 22:27:37 EST References: <273@bms-at.UUCP> Sender: daemon@cartan.Berkeley.EDU Reply-To: ballou@brahms (Kenneth R. Ballou) Organization: Math Dept. UC Berkeley Lines: 30 Keywords: What? Why? How? In article <273@bms-at.UUCP> stuart@bms-at.UUCP (Stuart D. Gathman) writes: >I am still confused about several things concerning pointers to arrays. > >There does seem to be such a type, even in K & R. > >1) How does one get such an animal? The only methods I can figure are > > a) a cast: ( type (*)[] ) array_of_type Also, you could have: int (* foo) [10]; foo = (int (*) [10]) malloc (4 * sizeof (int [10])) Then, * foo, * (foo + 1), * (foo + 2), and * (foo + 3) would each have type "array of 10 ints." > b) a function returning such a type (but the return must use a cast!) No, this function could now say return foo + 2; >3) It seems to me that any distinction between a pointer to an array > and a pointer to its first element is purely semantic. Nope, it affects address arithmetic. -------- Kenneth R. Ballou ...!ucbvax!brahms!ballou Department of Mathematics ballou@brahms.berkeley.edu University of California Berkeley, California 94720