The key to understanding C, especially if you’re coming at it from an embedded software context, is to approach the language from the perspective of the hardware. Most discussions of pointers in C start by talking about variables and then do some vague hand waving to introduce some deeply counter-intuitive and confusing abstractions around ‘indirection’ and ‘dereferencing’. To my mind, if you understand a little bit about the hardware (and if you’re developing in C the chances are you’re going to need that at some point) then pointers can be explained in a much more concrete fashion and it all makes a lot more sense.
Pointers are a way of getting access to data at a specified memory location so you should probably have at least a basic understanding of how memory is organised and how it works.
That’s the underlying hardware out of the way, because of course that’s all there is to it, so now we can move on to talk about how C implements access to memory. For that we need to talk about pointer operators.
We just glossed over the issue of types when we talked about pointer operations but it’s worth delving a little deeper into how C’s type system integrates with pointers. In addition if you step beyond the basic built-in types you need to be aware of how arrays, structs and pointers to pointers operate.
Now that we’ve covered the mechanics of pointers we should address the perennial question “Why should I use pointers?”
Explain the term ‘referential semantics’
What’s the difference between indirection and dereferencing?
What’s the difference between a variable and a pointer? Both are ‘indirections’. A pointer is a variable whose value is an address.
What’s the difference between an address and a pointer? Both can be used in the same places e.g. *(&value)
Three steps to declaring a variable: memory allocation, name linked to location, value set into memory.