int num = 45,*ptr1,*ptr2;
ptr1=#
ptr2=&ptr1;
printf("%d\n",*ptr1);
I've been thinking about this question for a while, but couldn't find a way to understand it,why &ptr1
can not be assigned to ptr2
in line 3, &ptr1
is a pointer's address,this address is no different from other address like an address of an integer, say
int a=1;
ptr2=&a;
Which means that I can assign an integer's address to a pointer,but not a pointer's address to a pointer,what differences between these two "address" could possibly make them different? Address of common variables can be assigned to single pointer,but address of pointers can not be assigned to single pointer?
I know the right way to do it is use double pointer to declare ptr2
,but why single pointer can't?
num
(which holds a int) useptr1=# ptr2=ptr1
if you want ptr1 pointing to the memory address of k, and ptr2 pointing to the memory address of ptr1 (which holds a pointer to an int) then you need a pointer of pointer. So, despite how much memory it takes to store ints and *ints, they are different mammals, with different contents. – Stopover