Array (data type)
≈ 6 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
In computer science, array is a data type that represents a collection of elements (values or variables), each selected by one or more indices (identifying keys) that can be computed at run time during program execution. Such a collection is usually called an array variable or array value. By analogy with the mathematical concepts vector and matrix, array types with one and two indices are often called vector type and matrix type, respectively. More generally, a multidimensional array (or n-dimensional array) type can be called a tensor type, by analogy with the mathematical concept, tensor. Language support for array types may include certain built-in array data types, some syntactic constructions (array type constructors) that the programmer may use to define such types and declare array variables, and special notation for indexing array elements. For example, in the Pascal programming language, the declaration , defines a new array data type called MyTable . The declaration var A: MyTable then defines a variable A of that type, which is an aggregate of eight elements, each being an integer variable identified by two indices. In the Pascal program, those elements are denoted A[1,1] , A[1,2] , A[2,1] , …, A[4,2] . Special array types are often defined by the language's standard libraries. Dynamic lists are also more common and easier to implement than dynamic arrays.…
In computer science, array is a data type that represents a collection of elements (values or variables), each selected by one or more indices (identifying keys) that can be computed at run time during program execution. Such a collection is usually called an array variable or array value. By analogy with the mathematical concepts vector and matrix, array types with one and two indices are often called vector type and matrix type, respectively. More generally, a multidimensional array (or n-dimensional array) type can be called a tensor type, by analogy with the mathematical concept, tensor. Language support for array types may include certain built-in array data types, some syntactic constructions (array type constructors) that the programmer may use to define such types and declare array variables, and special notation for indexing array elements. For example, in the Pascal programming language, the declaration , defines a new array data type called MyTable . The declaration var A: MyTable then defines a variable A of that type, which is an aggregate of eight elements, each being an integer variable identified by two indices. In the Pascal program, those elements are denoted A[1,1] , A[1,2] , A[2,1] , …, A[4,2] . Special array types are often defined by the language's standard libraries. Dynamic lists are also more common and easier to implement than dynamic arrays. Array types are distinguished from record types mainly because they allow the element indices to be computed at run time, as in the Pascal assignment . Among other things, this feature allows a single iterative statement to process arbitrarily many elements of an array variable. In more theoretical contexts, especially in type theory and in the description of abstract algorithms, the terms "array" and "array type" sometimes refer to an abstract data type (ADT) also called abstract array or may refer to an associative array, a mathematical model with the basic operations and behavior of a typical array type in most languages basically, a collection of elements that are selected by indices computed at run-time. Depending on the language, array types may overlap (or be identified with) other data types that describe aggregates of values, such as lists and strings. Array types are often implemented by array data structures, but sometimes by other means, such as hash tables, linked lists, or search trees. int a[10]; // array 'a' of 10 ints int* p = a; // 'p' points to the first element of 'a' void foo(int arr[]) { // the parameter 'arr' is an int[] // 'arr' is decayed to a pointer to its first element } However, in other languages, such as Java, an array is an actual type. For any type T , it has a corresponding array type T[] , which is an object with a length field. int[] a = new int[5]; // declares an array 'a' of 5 ints For one-dimensional arrays, this facility may be provided as an operation append(A,x) that increases the size of the array A by one and then sets the value of the last element to x. Other array types (such as Pascal strings) provide a concatenation operator, which can be used together with slicing to achieve that effect and more. In some languages, assigning a value to an element of an array automatically extends the array, if necessary, to include that element. In other array types, a slice can be replaced by an array of different size, with subsequent elements being renumbered accordingly as in Python's list assignment A[5:5] = [10,20,30] , that inserts three new elements (10, 20, and 30) before element "A[5]". Resizable arrays are conceptually similar to lists, and the two concepts are synonymous in some languages. An extensible array can be implemented as a fixed-size array, with a counter that records how many elements are actually in use. The append operation merely increments the counter; until the whole array is used, when the append operation may be defined to fail. This is an implementation of a dynamic array with a fixed capacity, as in the string type of Pascal. Alternatively, the append operation may re-allocate the underlying array with a larger size, and copy the old elements to the new area.
Text derived from https://en.wikipedia.org/w/index.php?oldid=1360426530 under CC BY-SA 4.0; modifications have been made.