Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!emory!att!ucbvax!hplabs!hpfcso!pgt From: pgt@hpfcso.FC.HP.COM (Paul G. Tobin) Newsgroups: comp.lang.c Subject: Re: Array question Message-ID: <7060009@hpfcso.FC.HP.COM> Date: 14 Feb 91 16:36:59 GMT References: Organization: Hewlett-Packard, Fort Collins, CO, USA Lines: 35 Michael Stefanik wrote: * One thing to point out is that pointers and arrays are _not_ interchangable * entities _except_ when you are passing them to functions. The moral is this: * when you mean to use a pointer, use a pointer; when you mean to use an array, * use an array. Michael, can you clarify this a little bit? I thought pointers and arrays in C _were_ interchangeable, which is often quite convenient. On pg. 94 of the original K&R, they state (this is a quote): "In fact, a reference to an array is converted by the compiler to a pointer to the beginning of the array. The effect is that an array name _is_ a pointer expression." On the previous page (93), section 5.3 opens with: "In C, there is a strong relationship between pointers and arrays, strong enough that pointers and arrays really should be treated simultaneously. Any operation which can be achieved by array subscripting can also be done with pointers. The pointer version will in general be faster but, at least to the uninitiated, somewhat harder to grasp immediately." It would seem that today's compilers probably somewhat close the speed gap between array and pointer addressing, but I'd contend that they *can* be freely interchanged. It all depends on your personal style. Use whatever mode seems more suited to the task at hand. Sorry for the drift, but the previous responses have aptly answered the question in the basenote. 3 responses without diverging from the original topic is too much :-). Paul Tobin pgt@hpfipgt.fc.hp.com