by dllthomas · 12y ago · 0 comments
I'm not sure how "address" is not a good, "simple real-world analogy" for pointers. It may be that I've just internalized enough of the behavior of pointers that I'm glossing over important differences, though... I struggled with pointers long enough ago that I don't remember struggling with pointers.
int b, *a;
declares that "b"
and "*a"
are ints only really breaks down at casts. It does require point out that you are allocating space for the named things, not the terms...I think it comes down to the address of an int* is a thing, which again makes sense to someone familiar, but to a newcomer means you have a thing at an address that is an address of another thing.
Maybe it's lost in the mists for me too, but if you don't know your pointers from yout references from your values... how can you code anything?
I've seen some awkward code too from people moving from Java to C++ where either they make everything a pointer, or they use value objects without understanding that they're not references.