Pointers finally made sense when I drew memory as a row of boxes
Think of memory as a long row of numbered boxes. A normal variable is a box holding a value. A pointer is a box holding the NUMBER of another box.
- &x asks "what's the number of x's box?"
- *p says "go to the box whose number is stored in p."
Arrays are then just consecutive boxes, and p + 1 means "the next box over" (scaled by the element size). Once I drew this out, pointer arithmetic stopped feeling like black magic.
Comments
Row of boxes is exactly how I think about it too.