In each diagram, a box labeled “a” is above a box labeled “p” at left. The variations for different lines of code are as follows:
IntPtr p;
int a[10];
“a” points to a row of 10 boxes at right, each containing a question mark; “p” contains a question mark.
for (index = 0; index < 10; index++)
a[index] = index;
Same as the diagram in (a), except the boxes at right contain the numbers 0 through 9 instead of question marks.
p = a;
Same as the diagram in (b), except “p” now also has an arrow pointing to the row of boxes instead of a question mark. A block of code below reads as follows:
for (index=0; index < 10; index++)
cout << p[index] << " ";
The second line of this block is annotated “Iterating through p is the same as iterating through a”. Below is the line "Output 0 1 2 3 4 5 6 7 8 9".
for (index = 0; index < 10; index++)
p[index] = p[index] + 1;
Same as the diagram in (c), except the row of boxes is numbered 1 through 10 instead of 0 through 9. A block of code below reads as follows:
for (index=0; index < 10; index++)
cout << a[index] << " ";
The second line of this block is annotated “Iterating through a is the same as iterating through p”. Below is the line "Output 1 2 3 4 5 6 7 8 9 1 0".