Item 8. Pointers to Pointers
It’s legal to declare a pointer to a pointer. This is what the C++ standard calls a “multilevel” pointer.
int *pi; // a ptrint **ppi; // a two-level multilevel ptrint ***pppi; // a three-level multilevel ptr
Although it’s rare to encounter multilevel pointers with more than two levels, we do see pointers to pointers in two common situations. The first is when we declare an array of pointers.
Shape *picture[MAX]; // array of ptr to Shape
Because an array name decays into a pointer to its first element (see Array Formal Arguments [6, 17]), the name of an array of pointers is also a pointer to a pointer.
Shape **pic1 = picture;
We most often see this usage in the implementation of a class that manages a buffer of pointers: ...
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