Variable-length array

Variable-length array

In programming, a variable length array (or VLA) is an array data structure of automatic storage duration whose length is determined at run time (instead of at compile time).

Programming languages that support VLAs include APL, COBOL, and C (added in C99).

Examples

The following C function allocates a variable-length array of a specified size, fills it with floating-point values, then passes it to another function for processing. Because the array is declared as an automatic variable, its lifetime ends when the read_and_process function returns.

float read_and_process(int n){ float vals [n] ;

for (int i = 0; i < n; i++) vals [i] = read_val(); return process(vals, n);}

The following COBOL fragment declares a variable-length array of records.

DATA DIVISION.WORKING-STORAGE SECTION.01 VAR-ITEM. 05 VAR-CNT PIC S9(4) BINARY. 05 VAR-PERSON OCCURS 0 TO 20 TIMES DEPENDING ON VAR-CNT. 10 VAR-NAME PIC X(20). 10 VAR-WAGE PIC S9(7)V99 PACKED-DECIMAL.

Languages such as C# and Java do not have variable-length arrays, because all arrays in those languages are dynamically allocated on the heap and therefore do not have automatic storage duration.


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Array data type — Not to be confused with Array data structure. In computer science, an array type is a data type that is meant to describe a collection of elements (values or variables), each selected by one or more indices that can be computed at run time by the …   Wikipedia

  • Array — In computer science an array [Paul E. Black, array , in Dictionary of Algorithms and Data Structures , Paul E. Black, ed., U.S. National Institute of Standards and Technology. 26 August 2008 (accessed 10 September 2008).… …   Wikipedia

  • Variable — A variable (pronEng|ˈvɛərɪəbl) is an attribute of a physical or an abstract system which may change its value while it is under observation. Examples include the height of a child, the temperature across a state, or the input to a function. This… …   Wikipedia

  • Array slicing — In computer programming, array slicing is an operation that extracts certain elements from an array and packages them as another array, possibly with different number of indices (or dimensions) and different index ranges. Two common examples are… …   Wikipedia

  • Variable range hopping — IntroductionVariable range hopping or Mott variable range hopping, is a model describing low temperature conduction in strongly disordered systems with localized states. [Mott, N.F., Phil. Mag. ,19,835,1969] It has a characteristic temperature… …   Wikipedia

  • Variable number tandem repeat — A Variable Number Tandem Repeats (or VNTR) is a location in a genome where a short nucleotide sequence is organized as a tandem repeat. These can be found on many chromosomes, and often show variations in length between individuals. Each variant… …   Wikipedia

  • Comparison of programming languages (array) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • Dynamic array — Several values are inserted at the end of a dynamic array using geometric expansion. Grey cells indicate space reserved for expansion. Most insertions are fast (constant time), while some are slow due to the need for reallocation (Θ(n) time,… …   Wikipedia

  • Halbach array — A Halbach array, showing the orientation of each piece s magnetic field. This array would give a strong field underneath, while the field above would cancel. The flux diagram of a Halbach array A Halbach array is a special arra …   Wikipedia

  • Generalized linear array model — In statistics, the generalized linear array model(GLAM) is used for analyzing the data sets with array structure. It based on the generalized linear model with the regression matrix written as a Kronecker product. Overview In the article… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”