Array
-
Why array starts with zero? Best wishes Nikesh
-
Why array starts with zero? Best wishes Nikesh
Because it's natural. -- the
C
developer ...Or [^]. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Why array starts with zero? Best wishes Nikesh
-
Why array starts with zero? Best wishes Nikesh
(probably not the best technical explanation, but...) because the first element is at a zero "offset" from the start of the array.
Watched code never compiles.
-
(probably not the best technical explanation, but...) because the first element is at a zero "offset" from the start of the array.
Watched code never compiles.
-
Maximilien wrote:
probably not the best technical explanation
But may well be the clearest :thumbsup:
It's time for a new signature.
:-O
Watched code never compiles.
-
Why array starts with zero? Best wishes Nikesh
it makes switching between
(pointer + offset)
andpointer[offset]
simple. if arrays started with 1,pointer[1]
would be the same aspointer + 0
, and C programs would be full of off-by-one errors as programmers forgot to account for the difference when switching between array notation andpointer + offset
notation.