Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Array-as-pointer Syntax Date: Thu, 28 Mar 2019 14:04:53 -0700 Organization: None to speak of Lines: 42 Message-ID: References: <761347c7-4f03-42f3-a156-5f357c8ae091@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="8cfa11d3fa0097ca58f89eca347894b2"; logging-data="32278"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mNvMuf29Qv+PKaN6eqygH" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:UTUqIOC/IeKNjbwzS7EqTu97CVA= sha1:xdqDega6xkrKXoyN6keMl7oamuU= Xref: csiph.com comp.lang.c:142568 "David T. Ashley" writes: > Given: > > int x[1000]; > > what is the difference between: > > memset(x, 0, sizeof(x)); > > and > > memset(&x, 0, sizeof(x)); > > I would think there is NO difference, but I might be missing something ... As others have explained, the pointer arguments are of different types, but they point to the same location, yielding the same value after the implicit conversion to the parameter type void*. The phrase "Array-as-pointer syntax" is a bit misleading. Strictly speaking, there's no such thing. It's true that in an expression like foo[42] the subexpression foo can be either of pointer type or of array type -- but in fact the index expression *always* requires one operand of pointer type and one of integer type. If the prefix happens to be an array name, it's implicitly converted to a pointer expression. Similarly, the first argument to memset() must be a pointer expression. If it's an array name, the argument expression is implicitly converted to a pointer expression. If you think this is all counterintuitive and confusing, I agree -- but it's important to understand it. See section 6 of the comp.lang.c FAQ http://www.c-faq.com/ -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */