This is an old version, view current version.
17.2 Slicing with range indexes
Slicing returns a contiguous slice of a one-dimensional array, a contiguous sub-block of a two-dimensional array, and so on. Semantically, it is just a special form of multiple indexing.
Lower and upper bound indexes
For instance, consider supplying an upper and lower bound for an index.
int c[7];
...
int d[4];
d = c[3:6]; // result: d == (c[3], c[4], c[5], c[6])
The range index 3:6
behaves semantically just like the multiple
index (3, 4, 5, 6)
. In terms of implementation, the sliced
upper and/or lower bounded indices are faster and use less memory
because they do not explicitly create a multiple index, but rather use
a direct loop. They are also easier to read, so should be preferred
over multiple indexes where applicable.