5 ms·
I wonder if pointers confuse people because C's syntax for pointers is confusing. The confusing examples always involve arrays, where a statically allocated ar
by drblast 16y ago
I wonder if pointers confuse people because C's syntax for pointers is confusing. The confusing examples always involve arrays, where a statically allocated array's behavior is different from one that's dynamically allocated and not necessarily what you would expect as a beginner, or where the vagaries of operator precedence obfuscate the pointer arithmetic.
I think the C++ programming book I first used made it worse by equating pointers and arrays from the start, making it seem like they were interchangeable.
At least for me, no other languages including assembler seemed to generate this amount of confusion over such a simple thing.
- cynicalkane 16y agoC style arrays are the lowest level model for flat arrays that I can imagine. Maybe it's more accurate to say that computers are confusing, and C is just being C.
- drblast 16y agoBut computers aren't confusing; the idea of a block of N bytes memory containing M-byte sized elements is dead-simple, and the same whether it's statically or dynamically allocated. The semantics associated with accessing those elements in C is anything but, especially for a beginner.
- cynicalkane 16y agoArrays are "dead simple", but addressing their elements can get very complicated, especially if you might want to address the array itself.
- shadowfox 16y agoCan you explain?
- deleted 16y ago[deleted]