[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Strange C behaviour



On 05-Apr-00, 11:06 (CDT), Andreas Fuchs <asf@acm.org> wrote: 
> On Tue, 4 Apr 2000 14:54:29 +0200, Michael Meskes <meskes@debian.org> said:
> > When I started learning C (okay, that's quite some 15 years ago) I think I
> > learned that an array is the same as a pointer. So I'd expect it to be
> > pointer to the pointer.

It isn't. Arrays are not pointers.

> [snip]
> So, you see: arrays _are_ pointers of a kind, just because an array
> is converted to a (constant) pointer when used in an
> expression. 

Arrays aren't pointers. Arrays decay (or are promoted, depending on your
point of view) into a pointer to the first element of the array in many
(but not all) circumstances.

I know I'm being pedantic, but the difference can be significant, and
just going around thinking "arrays are pointers" will lead to subtle
errors. It's better to actually understand the difference, when the
conversion happens, when it doesn't, and why it matters.

(We should take this to comp.lang.c if it's going to go on any further,
but before we do, read questions 6.2 - 6.9 in the comp.lang.c FAQ at
http://www.eskimo.com/~scs/C-faq/s6.html.)

Steve

-- 
Steve Greenland <stevegr@debian.org>
(Please do not CC me on mail sent to this list; I subscribe to and read
every list I post to.)


Reply to: