Another silly question

Phil Cornes pc at cs.keele.ac.uk
Wed May 17 03:22:28 AEST 1989


>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.


> If I mix two pointer types, as in
>   char * c;
>   long * ell;
>      return c + ell;
> is this anarchy?  Is it a syntax error?  What is sizeof(*(c+ell))?
> 

In this case the question doesn't make sense because the addition operators
function is undefined for two pointer type operands....



More information about the Comp.lang.c mailing list