Pointer conversions
Pointer conversions are performed when pointers are used, including pointer assignment, initialization, and comparison.
Beginning of C only.
Conversions that involve pointers must use an explicit type cast.
The exceptions to this rule are the allowable assignment conversions
for C pointers. In the following table, a
The referenced type of the left operand must have the same
qualifiers as the right operand. An object pointer may be an incomplete
type if the other pointer has type
const-qualified
lvalue cannot be used as a left operand of the assignment.
| Left operand type | Permitted right operand types |
|---|---|
pointer to (object) T |
|
pointer to (function) F |
|
void*.
End of C only.
- Zero constant to null pointer
- A
constant expression that evaluates to zero is a null pointer constant.
This expression can be converted to a pointer. This pointer will be
a null pointer (pointer with a zero value), and is guaranteed not
to point to any object.
A constant expression that evaluates to zero can
also be converted to the null pointer to a member. - Array to pointer
- An
lvalue or rvalue with type "array of N," where N is
the type of a single element of the array, to N
*. The result is a pointer to the initial element of the array. A conversion cannot be performed if the expression is used as the operand of the&(address) operator or thesizeofoperator. - Function to pointer
-
An lvalue that is a function can be converted to an rvalue that is a pointer to a function of the same type, except when the expression is used as the operand of the
&(address) operator, the()(function call) operator, or thesizeofoperator.