Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Zero-based numbering
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== {{Anchor|OFFSET}}Usage in programming languages === {{See also|Comparison of programming languages (array)#Array dimensions}} This usage follows from design choices embedded in many influential [[programming language]]s, including [[C (programming language)|C]], [[Java (programming language)|Java]], and [[Lisp programming language|Lisp]]. In these three, sequence types (C arrays, Java arrays and lists, and Lisp lists and vectors) are indexed beginning with the zero subscript. Particularly in C, where arrays are closely tied to [[pointer (computer programming)|pointer]] arithmetic, this makes for a simpler implementation: the subscript refers to an offset from the starting position of an array, so the first element has an offset of zero. Referencing memory by an address and an offset is represented directly in [[computer hardware]] on virtually all computer architectures, so this design detail in C makes compilation easier, at the cost of some human factors. In this context using "zeroth" as an ordinal is not strictly correct, but a widespread habit in this profession. Other programming languages, such as [[Fortran]] or [[COBOL]], have array subscripts starting with one, because they were meant as [[high-level programming language]]s, and as such they had to have a correspondence to the usual [[ordinal number (linguistics)|ordinal numbers]] which predate the [[0|invention of the zero]] by a long time. [[Pascal (programming language)|Pascal]] allows the range of an array to be of any ordinal type (including enumerated types). [[APL (programming language)|APL]] allows setting the index origin to 0 or 1 during runtime programmatically.<ref>{{cite journal |last1=Brown |first1=Jim |title=In Defense of Index Origin 0 |journal=ACM SIGAPL APL Quote Quad |date=December 1978 |volume=9 |issue=2 |page=7 |doi=10.1145/586050.586053 |s2cid=40187000}}</ref><ref>{{cite web |last1=Hui |first1=Roger |title=Is Index Origin 0 a Hindrance? |url=https://www.jsoftware.com/papers/indexorigin.htm |website=jsoftware.com |publisher=JSoftware |access-date=19 January 2015}}</ref> Some recent languages, such as [[Lua (programming language)|Lua]] and [[Visual Basic]], have adopted the same convention for the same reason. Zero is the lowest unsigned integer value, one of the most fundamental types in programming and hardware design. In computer science, [[0 (number)|zero]] is thus often used as the base case for many kinds of numerical [[recursion]]. Proofs and other sorts of mathematical reasoning in computer science often begin with zero. For these reasons, in computer science it is not unusual to number from zero rather than one. If an array is used to represent a cycle, it is convenient to obtain the index with a [[modulo operator|modulo function]], which can result in zero.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)