Pointer conversions

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

Begin 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 1. 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 or more cv-qualifiers as compared to those of the right operand.
End C only
Zero constant to null pointer
An integral constant expression that evaluates to zero is a null pointer constant. This expression can be converted to a pointer. This pointer is 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. This conversion is not performed if the expression is used as the operand of the address operator & or the sizeof operator C++ onlyor when the array is bound to a reference of the array typeC++ only.
Function to pointer

An lvalue that is a function can be converted to a C++11(prvalue)C++11 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.