Why Would You Use Pointers?
So far you've seen step-by-step details of assigning a variable's address to a pointer. In practice, though, you would never do this. After all, why bother with a pointer when you already have a variable with access to that value? The only reason for this kind of pointer manipulation of a variable is to demonstrate how pointers work.
Now that you are comfortable with the syntax of pointers, you can put them to good use. Pointers are used, most often, for three tasks:
Managing data on the heap
Accessing class member data and functions
Passing variables by reference to functions
The rest of this chapter focuses on managing data on the heap and accessing class member data and functions. In Hour 11, “References,” you will ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access