#: 9538 S3/Languages
17-Feb-91 00:35:53
Sb: #9534-the **p syntax in 'C'
Fm: Sandy Tipper 72060,76
To: SCOTT HOWELL 70270,641 (X)
Actually, it means two different but related things, depending on where
you find it. In both of your examples, it was in a declaration
statement, (the first was complicated bu the fact that it included
an initialization, and the second was the declaration of a function).
the simplest example of this type is : char **p; This is a declaration
of the variable p. The first (RIGHTmost) asterisk means that p is a
pointer. Fair enough, but a pointer to what? The second asterisk tells
us that the what is a pointer itself. So p is a pointer to a pointer.
But what is the pointer that p is pointing to pointing at? A char. So
p is a pointer to a pointer to char. In your example, the initialization
is of p, setting up p to contain the address of a variable (p points to
that variable). That variable had better be a pointer to char.
Later in the code, after the definitions and declarations have been all
done, the asterisk has a different meaning altogether: instead of explaining
what the variable being declared is, it is an operator, "doing" something
to the expression it is operating on. If i is an int, and p is a pointer to
int, and pp is a pointer to pointer to int, then follow this:
i = 4;
p = &i;
pp = &p;
Question: what is **pp ? First, read it as *(*pp) So pp is pointing to
p, so *pp evaluates as equivalent to p. And p is pointing to i, so *p
evaluates as equivalent to i. So **pp is equivalent to i. So **pp is 4.
See?
Sandy
|