3 ms·
"Give me the 1st item" --> a[1] "give me the 2nd item" --> a[2] "how many items are in the array?" 5 "what is the index of the last item?" 5 I am used to 0-
by dbtc 4y ago
"Give me the 1st item" --> a[1]
"give me the 2nd item" --> a[2]
"how many items are in the array?" 5
"what is the index of the last item?" 5
I am used to 0-indexed and prefer consistency... yet there is an undeniable consistency to 1-indexed.
You're the person who brings back a dozen bottles of milk from the store when you see that they have eggs ;)
- tromp 4y ago> "what is the index of the last item?" 5 Usually, the more interesting question is: What is the index of the next item (when extending the array)? Which is 5 in 0-based indexing.
- shoemakersteve 4y agoIs it? If you're doing low-level stuff maybe, but I really haven't done much of that so I'm not even sure I know what you mean by "extending" an array (presumably has something to do with allocating contiguous memory?) and I can't actually think of any situation off the top of my head where I would ever need "the last index + 1" what with array methods existing and all.