Here is what I'm trying:
int a,b;
int *ptr;
a = 123;
ptr = &a;
b = *ptr;
printf("&a is %p\n",&a);
printf("ptr points to %p\n",ptr);
printf("&ptr is %p\n",&ptr);
printf("&b is %p\n",&b);
Results in:
&a is 0x7ffee01fc828
ptr points to 0x7ffee01fc828
&ptr is 0x7ffee01fc818
&b is 0x7ffee01fc820
I expected &b to show the same address as &a... But that's not the case, so I tried:
int a,*b;
int *ptr;
a = 123;
ptr = &a;
b = ptr;
printf("&a is %p\n",&a);
printf("ptr points to %p\n",ptr);
printf("&ptr is %p\n",&ptr);
printf("&b is %p\n",&b);
This still results in an unexpected memory address for &b:
&a is 0x7ffee1cbd828
ptr points to 0x7ffee1cbd828
&ptr is 0x7ffee1cbd818
&b is 0x7ffee1cbd820
Can someone help me understand why I'm unable to get &b matching the same address as &ptr or &a?
Thanks!