21.5.  Pointer Arithmetic

[ fromfile: memoryaccess.xml id: pointerarithmetic ]

Example 21.4. src/arrays/pointerArith.cpp

[ . . . . ]
int main()  {
    using namespace std;
    int y[] = {3, 6, 9};
    int x = 12;
    int* px;
    px = y;  1
    cout << "What's next: " << *++px << endl;
    cout << "What's next: " << *++px << endl;
    cout << "What's next: " << *++px << endl;
    cout << "What's next: " << *++px << endl;
    return 0;
}

1

y, or any array name, is an "alias" for a pointer to the first element in the array




[87] In general, accessing memory beyond the boundary of an array produces undefined results and, because that is what we are doing (on purpose), the results are undefined.