Subscripting
Subscripting allows you to access individual elements, as well as groups of elements, from within vectors, matrices, and arrays. The simplest form of subscripting accesses a single element by using integers as the subscripts, as shown in the code below. As with built-in C and C++ arrays, indices begin at 0.
 
x = v(4) + 1; // Access element 4 in vector v
cout << M(2,3); // Print element 2,3 in matrix M
A(1,3,2) = 2; // Set element 1,3,2 in 3D array A to 2
 
You can also use subscripting to create new views that access groups of elements at the same time. With this kind of subscripting, you can create vectors, matrices, and arrays that refer to selected elements of a vector, matrix, or array, or you can perform an operation on selected elements. Subscripting groups of elements can virtually eliminate loops over vectors, matrices, and arrays. This in turn can streamline your code, allow optimized basic linear algebra subroutines (BLAS), and simplify porting to an array processor or other specialized hardware.
In the next two sections, we discuss two forms of subscripting. In Subscripting with Character Strings, we describe how to use character strings to subscript groups of elements. The resulting syntax is easy to read and understand, but unfortunately the subscripts cannot be dynamically altered very easily. This limits their usefulness to situations where the subscript is known at compile time. A more general way to achieve the same capabilities, using subscript classes, is discussed in Advanced Subscripting.