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
Array (data structure)
(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!
===One-dimensional arrays=== [[File:1D array diagram.svg|thumb|Diagram of a typical 1D array]] A one-dimensional array (or single dimension array) is a type of linear array. Accessing its elements involves a single subscript which can either represent a row or column index. As an example consider the C declaration <code>int anArrayName[10];</code> which declares a one-dimensional array of ten integers. Here, the array can store ten elements of type <code>int</code> . This array has indices starting from zero through nine. For example, the expressions <code>anArrayName[0]</code> and <code>anArrayName[9]</code> are the first and last elements respectively. For a vector with linear addressing, the element with index ''i'' is located at the address {{nowrap|''B'' + ''c'' Β· ''i''}}, where ''B'' is a fixed ''base address'' and ''c'' a fixed constant, sometimes called the ''address increment'' or ''stride''. If the valid element indices begin at 0, the constant ''B'' is simply the address of the first element of the array. For this reason, the [[C (programming language)|C programming language]] specifies that array indices always begin at 0; and many programmers will call that element "[[zero-based numbering|zeroth]]" rather than "first". However, one can choose the index of the first element by an appropriate choice of the base address ''B''. For example, if the array has five elements, indexed 1 through 5, and the base address ''B'' is replaced by {{nowrap|''B'' + 30''c''}}, then the indices of those same elements will be 31 to 35. If the numbering does not start at 0, the constant ''B'' may not be the address of any element. [[File:2D array diagram.svg|thumb|Diagram of a typical 2D array]]
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)