c++ – Array element. Terminological confusion


I always thought I knew what an array element was, but now I'm not sure. As we know, a classic fixed-size array consists of a set of cells. For instance:

int a[10] - массив из 10 ячеек типа int (каждая по sizeof(int) байт)

An array cell is an area of ​​memory that we can access by index. Its position in the array cannot be changed. Each cell stores a value (in our example, a scalar value).

Question: is an array element a synonym for a cell (memory area) or a synonym for a cell value? For example, is the statement "array elements can be swapped" true?

Interested in the answer in general and the answer for C ++ in particular.


Essentially, an array element is a separate variable. And the definition and meaning can be taken for it:

Variable – a named or otherwise addressed memory area, the name or address of which can be used to access the data in a variable (at a given address).

Here. That is, formally, this is a memory area. Cell.

But in spoken language, this meaning is observed only partially. Apparently, many (like me) do not make a significant distinction between these concepts, and some do not even suspect about it.

When we talk about operations with an array as such – "create an array of several elements", "add an element", "delete an element" – we can assume that they mean operations on cells.

Well, not in the sense that they are created or deleted, but in that memory is allocated or freed. Since the meanings there, in fact, do not play any role.

When it comes to processing algorithms, then value comes to the fore. And the phrase "swap the elements of the array" in the context of some algorithm, for example, sorting or encryption, will be understandable and correct. Or "find the maximum / minimum element" – here it is also clear that what is meant is not their physical location in memory or the index. =)

Scroll to Top