[ lower-bound : length : stride]

[ lower-bound : length : ]

[ lower-bound : length ]

[ lower-bound : : stride]

[ lower-bound : : ]

[ lower-bound : ]

[ : length : stride]

[ : length : ]

[ : length ]

[ : : stride]

[ : : ]

[ : ]

The array section must be a subset of the original array.

Array sections are allowed on multidimensional arrays. Base language array subscript expressions can be used to specify length-one dimensions of multidimensional array sections.

Each of the lower-bound, length, and stride expressions if speciﬁed must be an integral type expression of the base language. When evaluated they represent a set of integer values as follows:

{ lower-bound, lower-bound + stride, lower-bound + 2 * stride,... , lower-bound + ((length - 1) * stride) }

The length must evaluate to a non-negative integer.

The stride must evaluate to a positive integer.

When the size of the array dimension is not known, the length must be speciﬁed explicitly.

When the stride is absent it defaults to 1.

When the length is absent it defaults to ⌈⌈(size − lower-bound)∕stride⌉⌉, where size is the size of the array dimension.

When the lower-bound is absent it defaults to 0.

The precedence of a subscript operator that uses the array section syntax is the same as the precedence of a subscript operator that does not use the array section syntax.

a[0:6]

a[0:6:1]

a[1:10]

a[1:]

a[:10:2]

b[10][:][:]

b[10][:][:0]

c[42][0:6][:]

c[42][0:6:2][:]

c[1:10][42][0:6]

S.c[:100]

p->y[:10]

this->a[:N]

(p+10)[:N]

Assume a is declared to be a 1-dimensional array with dimension size 11. The ﬁrst two examples are equivalent, and the third and fourth examples are equivalent. The ﬁfth example speciﬁes a stride of 2 and therefore is not contiguous.

Assume b is declared to be a pointer to a 2-dimensional array with dimension sizes 10 and 10. The sixth example refers to all elements of the 2-dimensional array given by b[10]. The seventh example is a zero-length array section.

Assume c is declared to be a 3-dimensional array with dimension sizes 50, 50, and 50. The eighth example is contiguous, while the ninth and tenth examples are not contiguous.

The ﬁnal four examples show array sections that are formed from more general base expressions.

The following are examples that are non-conforming array sections:

s[:10].x

p[:10]->y

*(xp[:10])

For all three examples, a base language operator is applied in an undeﬁned manner to an array section. The only operator that may be applied to an array section is a subscript operator for which the array section appears as the postﬁx expression.