... *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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.