What is the difference between a pointer and a double pointer
Why would the second one ever be used?
char *a; //Points to a char
char **b; //Why doesn't this also point char
What is the difference between a pointer and a double pointer
Why would the second one ever be used?
char *a; //Points to a char
char **b; //Why doesn't this also point char
A "double pointer" is just a pointer to another pointer. In your example, a pointer that points to a pointer that points to a char.
EDIT Actually this was answered here.
First of all, let me tell you, double pointer is not a correct nomenclature for a pointer to pointer. At times, they can mean different things (double pointer == pointer to a double
) and create confusions.
A pointer points to a variable or a function. Now, a pointer itself is a variable, so there can be another pointer which points to the pointer variable. The later is called a pointer-to-pointer.
So, in case of
char *a;
a
is a pointer which points to a char
.
Thus,
char **b;
b
is a pointer which points to a char *
and hence, they are different.
You can write
b = &a;
b
is a pointer to a pointer to a char
. More common than most double pointers, since char *
is typically used to reference strings, and a char **
will point to that.