Simply put, pointers are not addresses, they are varibles representing an address with a type. So the types have be compatible for pointers to assign (with the exception of void *
generic pointer).
ptr2 = &ptr1;
ptr1
has a type of int *
, so &ptr1
has a type of int **
, it's not the same with ptr2
, which has a type of int *
.
Reference: C99 6.5.16.1 Simple assignment
both operands are pointers to qualified or unqualified versions of compatible types, and the type pointed to by the left has all the qualifiers of the type pointed to by the right.