Skip to content

Commit f8a0387

Browse files
author
Colin Robertson
committed
Fix 1082 recursion problem in printing sample
1 parent 83f3195 commit f8a0387

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

docs/cpp/references-to-pointers.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
2-
title: "References to Pointers"
3-
ms.date: "08/20/2018"
2+
title: "References to pointers"
3+
ms.date: "06/13/2019"
44
helpviewer_keywords: ["references, to pointers"]
55
ms.assetid: 4ce48b08-1511-4d2f-a31f-95f99eac0c70
66
---
7-
# References to Pointers
7+
# References to pointers
88

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.
1010

1111
## Example
1212

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.
1414

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.
1616

1717
```cpp
1818
// references_to_pointers.cpp
@@ -45,11 +45,11 @@ void PrintTree( BTree* btRoot );
4545
int main( int argc, char *argv[] ) {
4646
// Usage message
4747
if( argc < 2 ) {
48-
cerr << "Usage: Refptr [1 | 2]" << "\n";
48+
cerr << "Usage: " << argv[0] << " [1 | 2]" << "\n";
4949
cerr << "\nwhere:\n";
5050
cerr << "1 uses double indirection\n";
5151
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";
5353
return 1;
5454
}
5555

@@ -92,15 +92,15 @@ int main( int argc, char *argv[] ) {
9292
// PrintTree: Display the binary tree in order.
9393
void PrintTree( BTree* MybtRoot ) {
9494
// Traverse the left branch of the tree recursively.
95-
if ( btRoot->Left )
96-
PrintTree( btRoot->Left );
95+
if ( MybtRoot->Left )
96+
PrintTree( MybtRoot->Left );
9797

9898
// Print the current node.
99-
cout << btRoot->szText << "\n";
99+
cout << MybtRoot->szText << "\n";
100100

101101
// Traverse the right branch of the tree recursively.
102-
if ( btRoot->Right )
103-
PrintTree( btRoot->Right );
102+
if ( MybtRoot->Right )
103+
PrintTree( MybtRoot->Right );
104104
}
105105

106106
// Add1: Add a node to the binary tree.
@@ -143,15 +143,15 @@ int Add2( BTree*& Root, char *szToAdd ) {
143143
```
144144
145145
```Output
146-
Usage: Refptr [1 | 2]
146+
Usage: references_to_pointers.exe [1 | 2]
147147
148148
where:
149149
1 uses double indirection
150150
2 uses a reference to a pointer.
151151
152-
Input is from stdin.
152+
Input is from stdin. Use ^Z to terminate input.
153153
```
154154

155155
## See also
156156

157-
[References](../cpp/references-cpp.md)
157+
[References](../cpp/references-cpp.md)

0 commit comments

Comments
 (0)