difference between 'char *arr' and 'char arr []'

Sean Fagan seanf at sco.COM
Fri Oct 12 14:28:18 AEST 1990


In article <49140 at seismo.CSS.GOV> black at beno.CSS.GOV (Mike Black) writes:
>"The expression E1[E2] is identical (by definition) to *((E1)+(E2))..."
>2 paragraphs later, "...array names are CONVERTED to pointers" (my
>emphasis).  A seeming conflict for something that is identical.  

Uhm... no, it's not.  The syntax

	E1[E2]

works for pointers as well as arrays.  The normal use is

	ArrayName [ expr ];

Now, since array names are converted to pointers, we get

	(ArrayName_as_Pointer) [ expr ];

which is the same as

	*((ArrayName_as_Pointer) + (expr));

Where's the conflict?  Or don't people understand what was being said?  (I opt
for the latter, actually, but I tend to give novices one break 8-).)

-- 
-----------------+
Sean Eric Fagan  | "*Never* knock on Death's door:  ring the bell and 
seanf at sco.COM    |   run away!  Death hates that!"
uunet!sco!seanf  |     -- Dr. Mike Stratford (Matt Frewer, "Doctor, Doctor")
(408) 458-1422   | Any opinions expressed are my own, not my employers'.



More information about the Comp.lang.c mailing list