Your code is incorrect. This expression:
ptr2 = &ptr1;
Trying to make int * from int ** without a cast. Standard C prohibits such conversions without explicit casts.
The reason this is not allowed is because pointer types are not guaranteed by the standard for all of the same size - so the pointer to your pointer may not match the variable that you specified as a pointer to int .
Since pointers to any type can be implicitly converted to and from void * , you could write (correct, but probably confusing) similar code, in what in your question:
int num = 45; void *ptr1, *ptr2; ptr1 = # ptr2 = &ptr1;
But at the same time, you will need to transfer all type information in some other way:
printf("%d\n",*(int *)ptr1); printf("%d\n",*(int **)ptr2);
source share