// passing an array name as a pointer (and printing it as a pointer) // using it to update the array in place // shows pointer arithmetic in an integer array #include #include using namespace std; void subr (int* ip); int main() { int ar[10] = {10, 20}; int* ip; cout << "before: ar[0] = " << ar[0] << " ar[1] = " << ar[1] << endl; cout << "address of ar is " << ar << endl; ip = ar; cout << "value at that address is " << *ip << endl << endl; subr(ar); cout << "after: ar[0] = " << ar[0] << " ar[1] = " << ar[1] << endl << endl; subr(ar); cout << "finally: ar[0] = " << ar[0] << " ar[1] = " << ar[1] << endl; return 0; } void subr (int* jp) { cout << endl << "subr says: value of pointer jp is " << jp << endl; cout << "subr says: value at place jp points to is " << *jp << endl << endl; *jp = *jp + 1; *(jp+1) = *(jp+1) + 2; return; } /* output: before: ar[0] = 10 ar[1] = 20 address of ar is 0xffbefbb8 value at that address is 10 subr says: value of pointer jp is 0xffbefbb8 subr says: value at place jp points to is 10 after: ar[0] = 11 ar[1] = 22 subr says: value of pointer jp is 0xffbefbb8 subr says: value at place jp points to is 11 finally: ar[0] = 12 ar[1] = 24 */