I was talking to someone who was new to low-level languages ββand manual memory management today, and am doing my best to explain the pointers.
Then he 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 result of this:
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
This makes no sense to him, as vp should! = & Vp. I am ashamed to say that I do not know what is happening here. So what is going on here?
source share