```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 ``` ```#include #include static int five = 5; static int nine = 9; void takeInt(int x) { x = 0; } void takeIntRef(int &r) { r = 0; } void takePtr(int *p) { *p = 1; p = &five; } void takePtrToPtr(int **p) { **p = 789; *p = &five; } void takeRefToPtr(int *&rp) { *rp = 1; rp = &nine; } int main() { int n = 123; takeInt(n); // local copy is modified std::cout << n << std::endl; // 123 (value unchanged) takeIntRef(n); // value passed by reference, original is modified std::cout << n << std::endl; // 0 (assigned in function) int *pt = &n; // pt points to n takePtr(pt); // pointer is passed by value assert(pt == &n); // pointer has not changed (p still points to n) ... std::cout << n << std::endl; // 1 ... but pointee has takePtrToPtr(&pt); // pass a pointer to pt (= pointer to a pointer to n) assert(pt != &n); // this time the pointer has changed, // pt now no longer points to n std::cout << *pt << std::endl; // 5 assert(pt == &five); // indeed, pt points to the static "five" std::cout << n << std::endl; // 789 (changed in first line of takePtrToPtr) takeRefToPtr(pt); // pass a pointer by reference std::cout << *pt << std::endl; // 9 (pt is now modified in function) return 0; } ```
 ```1 2 3 4 5 6 ``` ```123 0 1 5 789 9 ```