/* Filename: arrayptr.cpp Author: Br. David Carlson Date: July 20, 1998 Last Revised: December 1, 2001 This program initializes an array of 10 integers and then prints out the data in two ways. First, it uses the usual count-controlled for loop, with array subscripting to access the data. Second, it uses a pointer variable to access the data and to control the loop. Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET g++ under Linux */ #include using namespace std; const int MAX = 10; typedef int * IntPtrType; int main(void) { IntPtrType DataPtr; int k, A[MAX] = {100, 90, 80, 70, 60, 50, 40, 30, 20, 10}; cout << "The items in array A, accessed via subscripting:" << endl; for (k = 0; k < MAX; k++) cout << A[k] << endl; cout << endl << "The items in array A, accessed via a pointer:" << endl; for (DataPtr = A; DataPtr < A + MAX; DataPtr++) cout << *DataPtr << endl; return 0; }