Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Zero-based numbering
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Zero-based numbering
(section)
Add topic