|
1 | 1 | --- |
2 | | -title: "References to Pointers" |
3 | | -ms.date: "08/20/2018" |
| 2 | +title: "References to pointers" |
| 3 | +ms.date: "06/13/2019" |
4 | 4 | helpviewer_keywords: ["references, to pointers"] |
5 | 5 | ms.assetid: 4ce48b08-1511-4d2f-a31f-95f99eac0c70 |
6 | 6 | --- |
7 | | -# References to Pointers |
| 7 | +# References to pointers |
8 | 8 |
|
9 | | -References to pointers can be declared in much the same way as references to objects. Declaring a reference to a pointer yields a modifiable value that is used like a normal pointer. |
| 9 | +References to pointers can be declared in much the same way as references to objects. A reference to a pointer is a modifiable value that's used like a normal pointer. |
10 | 10 |
|
11 | 11 | ## Example |
12 | 12 |
|
13 | | -The following code samples illustrate the difference between using a pointer to a pointer and a reference to a pointer. |
| 13 | +This code sample shows the difference between using a pointer to a pointer and a reference to a pointer. |
14 | 14 |
|
15 | | -Functions `Add1` and `Add2` are functionally equivalent (although they are not called the same way). The difference is that `Add1` uses double indirection whereas `Add2` uses the convenience of a reference to a pointer. |
| 15 | +Functions `Add1` and `Add2` are functionally equivalent, although they're not called the same way. The difference is that `Add1` uses double indirection, but `Add2` uses the convenience of a reference to a pointer. |
16 | 16 |
|
17 | 17 | ```cpp |
18 | 18 | // references_to_pointers.cpp |
@@ -45,11 +45,11 @@ void PrintTree( BTree* btRoot ); |
45 | 45 | int main( int argc, char *argv[] ) { |
46 | 46 | // Usage message |
47 | 47 | if( argc < 2 ) { |
48 | | - cerr << "Usage: Refptr [1 | 2]" << "\n"; |
| 48 | + cerr << "Usage: " << argv[0] << " [1 | 2]" << "\n"; |
49 | 49 | cerr << "\nwhere:\n"; |
50 | 50 | cerr << "1 uses double indirection\n"; |
51 | 51 | cerr << "2 uses a reference to a pointer.\n"; |
52 | | - cerr << "\nInput is from stdin.\n"; |
| 52 | + cerr << "\nInput is from stdin. Use ^Z to terminate input.\n"; |
53 | 53 | return 1; |
54 | 54 | } |
55 | 55 |
|
@@ -92,15 +92,15 @@ int main( int argc, char *argv[] ) { |
92 | 92 | // PrintTree: Display the binary tree in order. |
93 | 93 | void PrintTree( BTree* MybtRoot ) { |
94 | 94 | // Traverse the left branch of the tree recursively. |
95 | | - if ( btRoot->Left ) |
96 | | - PrintTree( btRoot->Left ); |
| 95 | + if ( MybtRoot->Left ) |
| 96 | + PrintTree( MybtRoot->Left ); |
97 | 97 |
|
98 | 98 | // Print the current node. |
99 | | - cout << btRoot->szText << "\n"; |
| 99 | + cout << MybtRoot->szText << "\n"; |
100 | 100 |
|
101 | 101 | // Traverse the right branch of the tree recursively. |
102 | | - if ( btRoot->Right ) |
103 | | - PrintTree( btRoot->Right ); |
| 102 | + if ( MybtRoot->Right ) |
| 103 | + PrintTree( MybtRoot->Right ); |
104 | 104 | } |
105 | 105 |
|
106 | 106 | // Add1: Add a node to the binary tree. |
@@ -143,15 +143,15 @@ int Add2( BTree*& Root, char *szToAdd ) { |
143 | 143 | ``` |
144 | 144 |
|
145 | 145 | ```Output |
146 | | -Usage: Refptr [1 | 2] |
| 146 | +Usage: references_to_pointers.exe [1 | 2] |
147 | 147 |
|
148 | 148 | where: |
149 | 149 | 1 uses double indirection |
150 | 150 | 2 uses a reference to a pointer. |
151 | 151 |
|
152 | | -Input is from stdin. |
| 152 | +Input is from stdin. Use ^Z to terminate input. |
153 | 153 | ``` |
154 | 154 |
|
155 | 155 | ## See also |
156 | 156 |
|
157 | | -[References](../cpp/references-cpp.md) |
| 157 | +[References](../cpp/references-cpp.md) |
0 commit comments