Home

ZeroBased

Zerobased, or zero-based indexing, is a convention in which the first element of an indexed sequence is assigned the index 0. In many programming languages and data structures, positions within arrays, lists, strings, and other sequences are referred to by nonnegative integers starting at 0.

The rationale for zerobased indexing traces back to memory addressing and pointer arithmetic. The offset from

Languages that use zerobased indexing include C, C++, Java, Python, JavaScript, Go, and Rust, among many others.

Advantages of zerobased indexing include straightforward address computation, consistency with pointer arithmetic, and support for end-exclusive

Related concepts include end-exclusive ranges and one-based indexing. Zerobased is a widely used default in many

---

the
base
address
of
a
sequence
often
maps
directly
to
the
element’s
index,
which
simplifies
calculations
and
implementation.
In
addition,
many
language
designs
apply
end-exclusive
ranges
in
loops
and
slices,
aligning
naturally
with
zero-based
indices.
Some
languages
or
domains
employ
different
bases
or
provide
alternative
views:
Lua
and
MATLAB,
for
example,
use
one-based
indexing
in
most
contexts,
while
others
offer
mixed
or
optional
indexing
schemes.
Even
within
a
language,
certain
APIs
may
present
1-based
counts
for
user-facing
data
while
internally
using
zerobased
indices.
ranges,
which
simplifies
loop
and
slice
construction.
Disadvantages
include
potential
off-by-one
errors
when
interfacing
with
human
users
or
external
systems
that
use
one-based
counting,
a
steeper
initial
learning
curve
for
beginners,
and
occasional
confusion
when
converting
between
counts
and
indices.
contemporary
languages,
shaping
common
patterns
for
iterating
and
accessing
sequence
elements.