3 ms·
Zero based indexing counts offsets. Literally in C, you are saying "add n times sizeof(T) to the base pointer and dereference it". It rather implies arrays are
by JulianMorrison 11y ago
Zero based indexing counts offsets. Literally in C, you are saying "add n times sizeof(T) to the base pointer and dereference it". It rather implies arrays are contiguous in storage and lack any "holes". It's a crude but close-to-the-metal approach. C arrays are not general, they are one specific structure. An array could be implemented as a tree, but C doesn't have built-in support for that.
One based indexing counts, or labels boxes. Counting implies no "holes", but abandons any implication about how they are laid out in storage. Labelling allows treating numerical arrays as sparse hash tables, with as many "holes" as needed. It's a high level view, suited to mathy ways of thinking about data.
- gct 11y agoYou can "label" by just agreeing that zero is in the set of counting numbers and labelling with those. Just because it's zero based doesn't mean it has to be an offset.