What is an array?

If you want to learn about the arrays of trees, then this article is not about that. But do not rush to close the article, it will help you to become even more erudite, because in addition to the arrays, you will learn what an array is in programming. Indeed, words have so many meanings that you can get confused ...

Array in programming

To gain understanding, let's start with the simplest definition of an array.

An array is a set of values ​​hidden under a specific name. That is, you can talk about a set of variables that have a particular value, and you can say about the set of these variables (homogeneous elements), each variable can be addressed by its index, or ordinal number (written in square brackets).

For clarity, we give an example from life. So the list of students in the journal will be an array. The sequence number of each student (usually they go alphabetically, that is, the names on the "A" will be the first) - this is his index.

Each array value (students in the example) is referred to as a component (or element).

Arrays are used to solve various programming tasks.

Types of arrays

We can talk about two types of arrays:

  1. one-dimensional;
  2. multidimensional.

However, one-dimensional and two-dimensional arrays are most often used in solving programming problems.

  • To visualize what a one-dimensional array is, imagine a tetrad sheet in a cell. So, any line vertically or horizontally (or even diagonally) is one-dimensional array. And the number of cells will determine the dimension of this one-dimensional array. In each element (cell) you can write a value (for example, a number), but only one (!). You can find this value by specifying its sequence number (in square brackets).
  • Consider what a two-dimensional array is all in the same example of a tetrad sheet in a cell. Several cells horizontally, several vertically - and we have formed some rectangular plate (for square read below). It will be a two-dimensional array. Here you can talk about the rows of the matrix (cells vertically) and columns (respectively, horizontal cells). As in a one-dimensional array, one value is stored in each cell. The difference is in finding the right value. Here you need to specify the line number and the column number, the intersection of which will give us the element we need.

A variant of a two-dimensional array is a square matrix, where the number of columns and rows is the same. In this case, the programming does not need to enter the number of rows and columns, it is enough to specify only the dimension of our matrix.

In a square matrix there are two types of diagonals:

  1. the main one is from the upper left to the lower right corner (i.e., where the row and column numbers are the same);
  2. side - goes from the upper right corner to the lower left.

To consolidate, we give another example from the life, illustrating the arrays.

So, residents of the entrance, - let it be an array under the name K.

The index here is the apartment number. This element (apartment) is another array - the tenants of the apartment. For example, in the 1st apartment there are 4 persons in the giver, in the 2nd - 3 persons, in the 3rd - 5 persons.

So, a one-dimensional array is an enumeration in square brackets (!) Of the number of residents: 4, 3, 5.

Two-dimensional array (instead of square brackets we will have “*”): ** 1, 1, 1, 1 *, * 1,1,1 *, * 1, 1, 1, 1, 1 **

Actually that's all. And what is a raid array, you can read.

Related news

What is an array image, picture, imagery


What is an array 67


What is an array 94


What is an array 38


What is an array 73


What is an array 100


What is an array 88


What is an array 47


What is an array 94


What is an array 2