Pointer question

Karl Heuer karl at haddock.ima.isc.com
Fri May 4 03:06:08 AEST 1990


In article <19515.263eadf8 at oregon.uoregon.edu> slewis at oregon.uoregon.edu writes:
>[Assuming declarations int i,j; int **p, *a, *b;] My understanding is that
>a[i] is equiv to *(a+i).  Now, this implies some strange things, right?
>First, since (pointer) addition is commutative, a[i] == *(a+i) == i[a].  I've
>seen this stated before in this newsgroup.

Right.

>But are the following assertions true:
>1.  p[i][j] == *( *(p+i) + j) == j[p[i]] == j[i[p]]
>2.  a[b[i]] == *( a + *(b+i)) == b[i][a] == i[b][a]

Looks right to me.  However, I maintain that, outside of the Obfuscated C
Contest, the identity a[i]==i[a] is worse than useless.  Never *ever* use it!

(I argued that X3J11 should have eliminated this misfeature, just as they did
with "a + = 1", but I wasn't convincing enough.)

Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint



More information about the Comp.lang.c mailing list