Pointer conversions

Pointer conversions are performed when pointers are used, including pointer assignment, initialization, and comparison.

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 const-qualified lvalue cannot be used as a left operand of the assignment.

Table 17. Legal assignment conversions for C pointers
Left operand type Permitted right operand types
pointer to (object) T
  • the constant 0
  • a pointer to a type compatible with T
  • a pointer to void (void*)
pointer to (function) F
  • the constant 0
  • a pointer to a function compatible with F

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 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. C++ only 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 the sizeof operator.
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 the sizeof operator.

Related information