Understanding C++ pointers (when they point to a pointer)
- by Stephano
I think I understand references and pointers pretty well. Here is what I (think I) know:
int i = 5; //i is a primitive type, the value is 5, i do not know the address.
int *ptr; //a pointer to an int. i have no way if knowing the value yet.
ptr = &i; //now i have an address for the value of i (called ptr)
*ptr = 10; //go get the value stored at ptr and change it to 10
Please feel free to comment or correct these statements.
Now I'm trying to make the jump to arrays of pointers. Here is what I do not know:
char **char_ptrs = new char *[50];
Node **node_ptrs = new Node *[50];
My understanding is that I have 2 arrays of pointers, one set of pointers to chars and one to nodes. So if I wanted to set the values, I would do something like this:
char_ptrs[0] = new char[20];
node_ptrs[0] = new Node;
Now I have a pointer, in the 0 position of my array, in each respective array. Again, feel free to comment here if I'm confused.
So, what does the ** operator do? Likewise, what is putting a single * next to the instantiation doing (*[50])? (what is that called exactly, instantiation?)