Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: $Revision: 1.6.2.14 $; site siemens.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!princeton!siemens!jrv From: jrv@siemens.UUCP Newsgroups: net.lang.c Subject: Re: Re: Pointers to arrays in C Message-ID: <32700004@siemens.UUCP> Date: Mon, 7-Apr-86 10:36:00 EST Article-I.D.: siemens.32700004 Posted: Mon Apr 7 10:36:00 1986 Date-Received: Wed, 9-Apr-86 23:34:26 EST References: <2389@brl-smoke.UUCP> Lines: 57 Nf-ID: #R:brl-smoke:-238900:siemens:32700004:000:1482 Nf-From: siemens!jrv Apr 7 10:36:00 1986 >It *is* a pointer to an array. Try running this program: > > main() > { > char (*x)[10]; > printf("%d\n%d\n%d\n", sizeof(*x), sizeof(x), sizeof((*x)[2])); > } > >It prints (on a VAX running ULTRIX): > >10 >4 >1 > >So, *x is an object of size 10 (the array), x is an object of size 4 (a >pointer), and (*x)[2] is a single byte (a char). C's strange type >syntax strikes again. > >Paul Dietz >dietz@slb-doll.csnet >/* End of text from siemens:net.lang.c */ When I learned C an instructor showed me a trick to use to keep straight in one's mind what a particular data construction was. To find out what data type something is go back to the original declaration of it cover over what you have in the expression and what is left is the data type. For example using the program above. sizeof(*x) char (*x)[10]; cover ^^^^ and you get an array of 10 characters sizeof(x) char (*x)[10]; cover ^ and you get a pointer to an array of 10 characters sizeof((*x)[2]) char (*x)[10]; cover ^^^^^^^^ and you get a character So by this "convention" C's syntax is consistent and the sizeof() operator worked as I would expect. Admittedly this scheme works easily on simple data types (hey, it was an intro class :-)) and there are some expressions which I have seen in net.lang.c on which I did not even attempt it. Jim Vallino Siemens Research and Technology Lab. Princeton, NJ {allegra,ihnp4,seismo,philabs}!princeton!siemens!jrv