a[i]
is defined as *(a+i)
, so yes, the []
subscript operator works with array and pointer expressions.
Except when it is the operand of the sizeof
or unary &
operators, or is a string literal used to initilialize another array in a declaration, an expression of type "N-element array of T
" is converted ("decays") to an expression of type "pointer to T
", and the value of the expression is the address of the first element of the array.
So, for an array a
, if you write a[i]
, the expression a
is converted from an array type to a pointer type, and the []
operator is applied to the resulting pointer expression. For a pointer p
, no conversion is necessary, and the []
operator is applied to p
directly.