Another silly question
Pete Holsberg
pjh at mccc.UUCP
Fri May 19 05:34:54 AEST 1989
In article <607 at kl-cs.UUCP> pc at cs.keele.ac.uk (Phil Cornes) writes:
=From article <17812 at cup.portal.com>, by Tim_CDC_Roberts at cup.portal.com:
=> Ok, folks. In regards to "a[i] == *(a+i) == *(i+a) == i[a]", let me
=> refer to the oft-used example 2["hello"].
=> I agree that this works and is equivalent to "hello"[2]. I've seen it
=> in books and postings. My simple question is why?
=
=C does not really support arrays, and the square bracket operator ([]) is
=just syntactic sugar to make you think that it does! This works quite well
=until you see things like "hello"[2] == 2["hello"] which only look odd if
=you continue to think of them as arrays and not pointers.
Can you explain why compilers produce different code for "a[i]" and "*(a+i)"?
Thanks.
--
Pete Holsberg, Mercer County Community College, Trenton, NJ 08690
More information about the Comp.lang.c
mailing list