4 ms·
One thing that helped me understand pointers was understanding that a pointer is just a memory address. When I was still a noob programmer, my instructor merel
by Sohcahtoa82 4y ago
One thing that helped me understand pointers was understanding that a pointer is just a memory address.
When I was still a noob programmer, my instructor merely stuck to words like "indirection" and "dereferencing" which are all fine and dandy, but learning that a pointer is just a memory address instantly made it click.
Pointers are a $1000 topic for a $5 concept.
- Koshkin 4y agoWell there’s a little bit more to it. There is a type involved, and then there’s pointer arithmetic.
- Sohcahtoa82 4y agoWell yes, but those aren't hard. Pointer arithmetic is merely knowing that any addition/subtraction done to a pointer is multiplied by the size of the type being pointed to. So if you're pointing to a 64-byte struct, then "ptr++;" adds 64 to the pointer.
- int_19h 4y agoTyped pointers interact with aliasing in "interesting" ways.
- sramsay 4y agoWhen I’m teaching (a very high-level language), I make a point of saying that a variable is a named memory location. Where is that location? We don’t know. Now, I am absolutely aware that the address isn’t the “real” location, but I have this idea that talking about variables in this way might help them grok the lower-level concept later on.