Home>Article> What is the difference between one-dimensional array and two-dimensional array?

What is the difference between one-dimensional array and two-dimensional array?

Guanhui
Guanhui Original
2020-06-15 10:59:22 7190browse

What is the difference between one-dimensional array and two-dimensional array?

What is the difference between one-dimensional array and two-dimensional array?

Each element in a one-dimensional array has only one subscript, which is essentially a linear collection of the same type of data, while each element in a two-dimensional array can be used as an array , which is essentially an array with arrays as array elements.

Array array

The so-called array is an ordered sequence of elements. If a limited collection of variables of the same type is named, then the name is the array name. The individual variables that make up an array are called components of the array, also called elements of the array, and sometimes called subscript variables. The numeric number used to distinguish the individual elements of an array is called a subscript. In programming, an array is a form of organizing several elements of the same type in an orderly manner for the convenience of processing. These ordered collections of similar data elements are called arrays.

Array is a collection used to store multiple data of the same type.

Source of array

In C language, array is a constructed data type. An array can be decomposed into multiple array elements, which can be basic data types or constructed types. Therefore, according to the type of array elements, arrays can be divided into various categories such as numerical arrays, character arrays, pointer arrays, and structure arrays.

Regarding the problem of variable length arrays (VLA): The original C89 standard does not allow variable length arrays to appear, but in the C99 standard, support for VLA has been added, but the supported compilers Not much, and due to the security issue of stack overflow, not many people dare to use this variable-length array, so it is defined as an optional implementation function in the C11 standard.

If you have experience programming in other languages, you must be familiar with the concept of arrays. Thanks to arrays, you can refer to a series of variables with the same name and identify them numerically (indexed). In many situations, using arrays can shorten and simplify programs because you can design a loop using index values to handle multiple situations efficiently. Arrays have upper and lower bounds, and the elements of the array are continuous within the upper and lower bounds. Because Visual Basic allocates space for each index value, do not declare an array that is unrealistically large.

The array here is an array of variables declared in the program. They differ from control arrays, which are specified at design time by setting the control's Index property. Variable arrays are always contiguous; unlike control arrays, array elements cannot be loaded or unloaded from the middle of an array.

All elements in an array have the same data type (this is true in C, C, Java, and pascal. But this is not the case in all places involving arrays. For example, arrays in Visual Foxpro are not There is no such requirement). Of course, when the data type is Variant, each element can contain different kinds of data (object, string, value, etc.). Arrays of any basic data type can be declared, including user-defined types and object variables.


Recommended tutorial: "PHP"


The above is the detailed content of What is the difference between one-dimensional array and two-dimensional array?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is Micro Rabbit? Next article:What is Micro Rabbit?