... *yPtr = 9;

which would assign 9 to y in Fig. 8.3—in the preceding statement, *yPtr is an alias for y. The dereferenced pointer may also be used to receive an input value as in

cin >> *yPtr;

which places the input value in y.

Common Programming Error 8.2

Dereferencing an uninitialized pointer results in undefined behavior that could cause a fatal execution-time error. This could also lead to accidentally modifying important data, allowing the program to run to completion, possibly with incorrect results.


Error-Prevention Tip 8.2

Dereferencing ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.