The array names is not modifiable lvalue so operation ++ is not applied hence ++a
that try to modify a
is compilation time error (where a
is array name).
Note *(a + 1)
and *a++
are not same, a + 1
is a valid instruction as it just add 1
but doesn't modify a
itself, Whereas ++a
(that is equvilent to a = a + 1
) try to modify a hence error.
Note 'array names' are not pointer. Pointers are variable but array names are not. Of-course when you assign array name to a pointer then in most expressions array names decays into address of first element. e.g.
int *p = a;
Note p
points to first element of array (a[0]
).
Read some exceptions where array name not decaying into a pointer to first element?
An expression a[i]
is equivalent to *(a + i)
, where a
can be either a pointer or an array name. Hence in your second example p[i]
is valid expression.
Additionally, *++p
is valid because because p
is a pointer (a variable) in second code example.