c/language/operator member access

Member access operators allow access to the members of their operands.

Subscript
The array subscript expression has the form

where

The subscript operator expression is an whose type is the type of the object pointed to by.

By definition, the subscript operator is exactly identical to. If is an array expression, it undergoes  and becomes a pointer to the first element of the array.

Due to the definition of the, the result is the element of the array with the index equal to the result of (or, if  was pointing at ith element of some array, the index of the result is i plus the result of )

Note: see for the details on multidimensional arrays.

Dereference
The dereference or indirection expression has the form

where

If is a pointer to function, the result of the dereference operator is a function designator for that function.

If is a pointer to object, the result is an  that designates the pointed-to object.

Dereferencing a null pointer, a pointer to an object outside of its lifetime (a dangling pointer), a misaligned pointer, or a pointer with indeterminate value is undefined behavior, except when the dereference operator is nullified by applying the address-of operator to its result, as in.

Address of
The address-of expression has the form

@1@ address of a function @2@ address of an object @3@ special case: and  cancel each other, neither one is evaluated @4@ special case: and the  that is implied in  cancel each other, only the addition implied in  is evaluated.

where

The address-of operator produces the address of its operand, suitable for initializing a pointer to the type of the operand. If the operand is a function designator, the result is a pointer to function. If the operand is an object, the result is a pointer to object.

If the operand is the dereference operator, no action is taken (so it's okay to apply &* to a null pointer), except that the result is not an lvalue.

If the operand is an array index expression, no action is taken other than the array-to-pointer conversion and the addition, so &a[N] is valid for an array of size N (obtaining a pointer one past the end is okay, dereferencing it is not, but dereference cancels out in this expression).

Member access
The member access expression has the form

where

The member access expression designates the named member of the or  designated by its left operand. It has the same as its left operand.

If the left operand is or  qualified, the result is also qualified. If the left operand is, the behavior is undefined.

Note: besides identifiers that name objects of struct or union type, the following expressions may have struct or union types:, , , , and.

Member access through pointer
The member access expression has the form

where

The member access through pointer expression designates the named member of the or  type pointed to by its left operand. Its value category is always

If the type pointed to by the left operand is or  qualified, the result is also qualified. If the type pointed to by the left operand is, the behavior is undefined.