Pointer variables simply point to other variable addresses in memory. And pointer variables have their own address in memory.
However, this code gives the same memory address for both.
int num=10;
int *ptr=#
printf("Address of variable num: %p\n",ptr);
printf("Address of pointer ptr: %d\n",&ptr);
If you print both of them at the same time, then it works as expected.
Num variable address: 0028FF3C
Ptr Pointer Address: 0028FF38
But if I print them one at a time, then it gives the same address for both.
printf("Address of variable num: %p\n",ptr);
//printf("Address of pointer ptr: %d\n",&ptr);
Variable num address: 0028FF38
//printf("Address of variable num: %p\n",ptr);
printf("Address of pointer ptr: %d\n",&ptr);
Ptr Pointer Address: 0028FF38
I am using the mingw compiler on a windows 7 machine.
source
share