Individual Elements
The simplest way to examine and change a matrix element is to use the operator()(int,int) function, where the first argument gives the row, and the second argument gives the column. As with built-in C-style arrays, the first row or column is indexed with 0. For example, given a matrix A, the notation A(2,3) refers to row 2, column 3. Because numbering starts from 0, this is actually the third row and fourth column.
In the next example, the code prints the value of row 0, column 2, of the matrix A (A(0,2)), and then sets row 2, column 0 (A(2,0)) to 6:
 
cout << A(0,2) << endl;
A(2,0) = 6;
This code compiles correctly for any type of matrix A, and generally behaves correctly. However, there are two situations in which a runtime error could occur. These are discussed in the next two sections.