Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 20 Feb 2012 16:32:27 -0600 Message-ID: <4F42C9FB.2597@mindspring.com> Date: Mon, 20 Feb 2012 17:32:27 -0500 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: Arrays Vs Pointers References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 36 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.156.231.83 X-Trace: sv3-MvPLJKRInMWD+J4Hqd++ztNpSwNYQZXI24kljkiFWO976HXF9RLIgVJEgfPWHL3u2Fb5HvFICRkfjft!MNejYgIqWxAJ+NNmZiC6h0VFTmV5cTCtgH0b/eeqMhPIH1wK1pHnYXxZs6Viy+Or4tmZuIxO6VLU!kVZPH5D+4A== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2144 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:17705 Keith Thompson wrote: > > Willem writes: > > peter wrote: > > ) I am currently exploring the world of pointers and have encounter some > > ) inconsistent information regarding the best way to reference an > > ) array: array[1] OR *(array +1). > > ) > > ) One book says that you should not use the syntax array[1] because > > ) of performance reason. > > > > That book is completely and utterly wrong. > > In C, "array[index]" is *exactly the same* as "*(array + index)" > > I would go so far as to call it syntactic sugar. > > Hell, it's even commutative. "array[index]" means the same as "index[array]" ! > [...] > > Yes, but I doubt that that's what the book actually said. Teach Yourself C, by Herbert Schildt, copyright 1990, Chapter 6.3, Use Pointers With Arrays, page 197: For somewhat complex reasons, a C compiler will generally create faster executable code for an expression such as *(p+3) than it will for the comparable array index p[3] -- pete