cpp/language/array

Declares an object of array type.

Syntax
An array declaration is any simple declaration whose has the form

A declaration of the form, declares as an array object that consists of  contiguously allocated objects of type. The elements of an array are numbered, and may be accessed with the , as in , …,.

Arrays can be constructed from any (except ), s,, , , or from other arrays of known bound (in which case the array is said to be multi-dimensional). In other words, only object types except for array types of unknown bound can be element types of array types. Array types of incomplete element type are also incomplete types.

There are no arrays of references or arrays of functions.

Applying to an array type (through typedef or template type manipulation) applies the qualifiers to the element type, but any array type whose elements are of cv-qualified type is considered to have the same cv-qualification.

When used with, the size of an array may be zero; such an array has no elements:

Assignment
Objects of array type cannot be modified as a whole: even though they are (e.g. an address of array can be taken), they cannot appear on the left hand side of an assignment operator:

Array-to-pointer decay
There is an from lvalues and rvalues of array type to rvalues of pointer type: it constructs a pointer to the first element of an array. This conversion is used whenever arrays appear in context where arrays are not expected, but pointers are:

Multidimensional arrays
When the element type of an array is another array, it is said that the array is multidimensional:

Note that when array-to-pointer decay is applied, a multidimensional array is converted to a pointer to its first element (e.g., a pointer to its first row or to its first plane): array-to-pointer decay is applied only once.

Arrays of unknown bound
If is omitted in the declaration of an array, the type declared is "array of unknown bound of T", which is a kind of, except when used in a declaration with an :

Because array elements cannot be arrays of unknown bound, multidimensional arrays cannot have unknown bound in a dimension other than the first:

If there is a preceding declaration of the entity in the same scope in which the bound was specified, an omitted array bound is taken to be the same as in that earlier declaration, and similarly for the definition of a static data member of a class:

References and pointers to arrays of unknown bound can be formed, be initialized or assigned from arrays and pointers to arrays of known bound. Note that in the C programming language, pointers to arrays of unknown bound are compatible with pointers to arrays of known bound and are thus convertible and assignable in both directions.

Pointers to arrays of unknown bound cannot participate in and cannot be used on the left of the, but can be dereferenced.

Array rvalues
Although arrays cannot be returned from functions by value and cannot be targets of most cast expressions, array may be formed by using a type alias to construct an array temporary using.

Array may be formed directly by accessing an array member of a class rvalue or by using std or another cast or function call that returns an rvalue reference.