// ptr8.cpp By: Aiman Hanna - ©1993-2006 Aiman Hanna // This program illustrates how pointers can be passed as parameters to functions. How // this can be related to passing parameters by reference? // // Key points: 1) Passing pointers as function parameters. #include void Twice(int *ptr, int ind1 , int ind2) { *(ptr + ind1) *= 2; // Same as a[ind1] if a is an array and ptr = a *(ptr + ind2) *= 2; } int main() { int a[3], *p = new int; a[0] = 4; a[1] = 5; a[2] = 7; p = a; cout << " This is the array before applying \"Twice\".... \n"; for ( int i = 0 ; i < 3 ; i++ ) cout << a[i] <<"\n"; Twice(p , 0 , 2); cout << "\n This is the array after applying \"Twice\".... \n"; for ( i = 0 ; i < 3 ; i++ ) cout << a[i] <<"\n"; return 0; } // The following is the result of compilation //Compilation successful // The following is the result of running the program /* This is the array before applying "Twice".... 4 5 7 This is the array after applying "Twice".... 8 5 14 */