int a[100], *p ; p = a ;is a perfectly valid declaration and statement and makes
p
point
to the integer a[0]
.
Furthermore, we can actually index the pointer p
.
Continuing with the example above, the expressions p[5]
and
a[5]
refer to exactly the same integer and p[125]
and
a[125]
are both invalid references.
We'll see in the later sections other aspects of the connection between arrays and pointer. Things begin to get really complex when we look at the similarities and differences between arrays of pointers and multi-dimensional arrays (which are arrays of arrays).
In the code fragment:p = &a[10] ; printf( "%d\n", p[5] ) ;which position in the array
a
will be printed?