4 ms·
In my experience the harder thing is the stack/heap memory model. It’s easy enough to get someone to understand that the variable “points” to another variable
by jakear 6y ago
In my experience the harder thing is the stack/heap memory model.
It’s easy enough to get someone to understand that the variable “points” to another variable like a house address or whatever. But, trying to explain that once a return happens the thing that was pointed to will potentially be gone entirely and you probably wont know immediately, or at least until you call another function, unless you allocated it with malloc, but in that case you need to be sure to call free at some point later, but watch out don’t call free twice, and hey there’s some analysis tools you can use with gdb to help find these types of issues, oh yeah gdb is this debugger it has its own special syntax you’ll want to learn than too, etc etc etc.
It’s so much easier to say: oh, you want to make a tree? Just make some leafy nodes and make some branchy ones point to them and you’ll literally never see segfault in your life. The pointers are still there, but the trouble is gone.
- nicoburns 6y agoC's point syntax doesn't help either. It's fine if you just have one pointer. But a few of them nested with some functions in the mix. Oh my. Oh, and basic primitives like arrays and strings in C are far more complex (and easier to get wrong) than pretty much every other language. And it doesn't have a built in map type at all!