// ptr4.cpp By: Aiman Hanna - ©1993-2006 Aiman Hanna // This program explains how pointers and arrays are related. // // Key Points: 1) Pointers and arrays. #include int main() { int a[5]; a[0] = 19; a[1] = 23; a[2] = 7; a[3] = 34; a[4] = 12; int *p = new int; p = a; cout << a[0] << "\n"; cout << *p << "\n"; cout << a[3] << "\n"; cout << *(p+3) << "\n\n"; cout << "The contents of the array are: \n" << endl; for ( int i = 0 ; i < 5 ; i++ ) cout << a[i] <<"\n"; cout << "\nThe contents of the array are: " << endl; for ( i = 0 ; i < 5 ; i++ ) cout << *(p+i) << "\n"; return 0; } // The following is the result of compilation // Compilation successful // The following is the result of running the program /* 19 19 34 34 The contents of the array are: 19 23 7 34 12 The contents of the array are: 19 23 7 34 12 */