Path: utzoo!mnetor!uunet!husc6!bbn!uwmcsd1!ig!jade!ucbvax!cbosgd!osu-cis!tut!lvc From: lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani) Newsgroups: comp.lang.c Subject: Re: Address of Array Message-ID: <3420@tut.cis.ohio-state.edu> Date: 21 Dec 87 14:25:17 GMT Organization: Ohio State Computer & Info Science Lines: 63 Summary: do I have it right now? After think about array address a bit, I see how silly I have been in thinking they were silly. Most of this is obvious, but here it is anyway. Maybe someone else will benefit from this too. Here is what I hope is a correct interpretation of array address. This is mostly borrowed from other postings. Thanks to Torek, Throop, Butterworth, Gwyn, and Heuer, etc. 1) Every object has an address. Arrays are objects, so they must have addresses. 2) The name of an array is a synonym for the address of the first element of the array. This is only a CONVENIENCE so you can write: for (p = name; p < &name[NTHINGS]; p++); instead of having to write: for (p = &name[0]; p < &name[NTHINGS]; p++); 3) The name of an array is NOT a synonym for the address of the array. 4) When you indirect a pointer to an array, you get an ARRAY. 5) When you increment (decrement) a pointer to an array, you point to the "next" ("previous") array. 6) Given: int ident[4]; The value of &ident might NUMERICALLY happen to equal &ident[0] but they are different because they have different TYPES. &ident is of type (int *)[4], and &ident[0] is of type (int *). 7) Given: int ident[2][4], (*pai)[4] = &ident[0]; pai++ would be equal to &ident[1] pai = &ident[3]; pai-- would be equal to &ident[2]; 8) ANSI C will allow: int ident[2][4], (*pai)[4] = &ident[0]; but not: int ident[2][4], (*pai)[5] = &ident[0]; Now, a question on ANSI C. Will you be able to do this: int ident[2][4]; int (*pai)[4] = &ident[0]; int (*pbi)[4] = &ident[1]; code that manipulates ident[0] *pbi = *pai; Thanks for all the info. -- Larry Cipriani AT&T Network Systems at cbosgd!osu-cis!tut!lvc Ohio State University