I was talking to someone who was new to low level languages, and manual memory management today and doing my best to explain pointers.
He then came up with:
#include <stdio.h>
int main()
{
int v = 0;
void* vp = &v;
int i = 0;
for(; i < 10; ++i)
{
printf("vp: %p, &vp: %p\n", vp, &vp);
vp = &vp;
}
}
The output of this is:
vp: 0xbfd29bf8, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
Which makes no sense to him as vp should != &vp. I'm ashamed to say that I don't know what's going on here.. so, what's going on here?