From 092c389e4ba45b727d122961c14af89d7e6eb3ce Mon Sep 17 00:00:00 2001 From: coco3427 Date: Tue, 13 May 2025 13:11:34 -0400 Subject: [PATCH] fixes issue #198 Needs review because it makes some changes the the code rior to the question and the last section to make the question and text match --- pretext/AtomicData/Pointers.ptx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pretext/AtomicData/Pointers.ptx b/pretext/AtomicData/Pointers.ptx index 5e5cb22..2d8acc2 100644 --- a/pretext/AtomicData/Pointers.ptx +++ b/pretext/AtomicData/Pointers.ptx @@ -212,7 +212,7 @@ int main( ) { better error handling with the keyword. The null pointer is often used in conditions and/or in logical operations.

The following example demonstrates how the null pointer works. - The variable ptrx initially has the address of x when it is declared. + The variable pntrN initially has the address of varN when it is declared. On the first iteration of the loop, it is assigned the value of nullptr, which evaluates to a false value; thereby ending the loop:

@@ -225,15 +225,15 @@ using namespace std; //Shows the use of a Null pointer to represent "nothing". int main( ) { - int x = 12345; - int *ptrx = &x; + int varN = 100; + int *pntrN = &varN; - while (ptrx) { - cout << "Pointer ptrx points to " << &ptrx << endl; - ptrx = nullptr; + while (pntrN) { + cout << "Pointer pntrN points to " << &pntrN << endl; + pntrN = nullptr; } - cout << "Pointer ptrx points to nothing!\n"; + cout << "Pointer pntrN points to nothing!\n"; } @@ -249,14 +249,14 @@ int main( ) { -

If the lines (varN = 50;) and (cout << *ptrN << endl;) were inserted into line 7-8, what would it cout?

+

If the lines (varN = 50;) and (cout << "ptrN: " << *ptrN << endl;) were inserted between lines 7 and 8, what would it cout?

-

varPntr: 9

+

pntrN: 100

Not quite, the variable varN no longer equals 100 past line 7!

@@ -265,7 +265,7 @@ int main( ) { -

varPntr: 50

+

pntrN: 50

Right!

@@ -274,7 +274,7 @@ int main( ) { -

varPntr: 150

+

pntrN: 150

No, the values do not add together!