by andyjohnson0 · 2y ago · 0 comments
I remember being very confused for a time by C pointers as an undergrad in the late 80s - a situation that none of my teachers really helped with. Eventually I realised that they were just memory addresses, and a whole lot of confusion collapsed into a simple concept. I still remember what that felt like in my head.
Turned out that many of my peers had a similar experience, and not all of them got through it.
So I'm wondering yet again: why do people find C pointers so difficult to grok? Is it conceptual (indirection), notational (& and *, arrays as pointers, etc), or something else?
(Pre-uni I'd devoted a lot of effort to getting VIC and SID chips to do stuff with peek and poke commands, and writing some assembly language, which I reckon did me no harm when I first encountered C - even though I probably didn't immediately recognise the connections. I do wonder what the contemporary equivalent is.)
For me, understanding pointers to data types was not the hard bit(int* or some_struct*), but wrapping my head around *array being a pointer to the first part of a contiguous segment of memory took a lot of time. Once that idea(and what ++array_pointer really did) settled in my head, pointers felt fairly normal to deal with.
I mean, it kind of makes sense but it's not obvious.
I think people need some background of computer architecture and operating systems before working with pointers, then instead of "what the heck are these addresses?" you get "oh that's how I can use all of these addresses, finally, yay, pointers" moment. If you just learn C/Cpp and related without the background, it's some magical and cumbersome feature.