5 ms·
What about this analogy? You have a piece of paper with a street address on it (the pointer value). You go to that street address (derefence the pointer), open
by ryl00 8y ago
What about this analogy? You have a piece of paper with a street address on it (the pointer value). You go to that street address (derefence the pointer), open the mailbox, and inside is another piece of paper with what you're actually looking for (like someone's name). For pointers to pointers, add another level of indirection..
- vram22 8y agoAnd after you've learned that (basics of pointers in C), a nice quick test of your knowledge (but not a comprehensive one) can be to read this standard declaration of main() in C (based on ANSI C, BTW, as described in 2nd edition of K&R C book, not sure if changed in later versions of standard): int main(int ac, char **av) and then try to figure what the following mean (what type they are, and whether each of them is a pointer or a pointed-to thing, or both: av *av **av av[0] etc. I was once teaching a class on C to a group of experienced programmers (10+ years each, but new to C), and after I explained the char **av stuff, one of them said "Now it is overhead transmission" :)
- Vindicis 8y agoI don't think really anyone has difficulty understanding the concept of a pointer. It's their usage that trips people up, and that most tutorials I've seen gloss over, which is where all the confusion stems from.
- ovao 8y agoExactly. There is the concept and the syntax of pointers, and those are relatively straightforward to understand. I gave up on learning C++ — twice — when I was a kid because no book explained why there are pointers. It’s all very “a pointer points to something! Now on to the next chapter.” (The third time was the charm, luckily.) One simple example showing value semantics would’ve made it click for me, and things only get more interesting when you talk about performance.