shaolinfunk
asked on
What is ** and *&?
Ok I'm familiar with pointers (*) and with references (&)...
but this is something new to me ...
What does it mean when I see **...as in "void ** FunctionName" or
*& as in "SentMail*& Envelope"?
Can you tell me what ** and *& do?
My guess is that it's a pointer to a pointer, and a pointer to a reference...but if I'm right WHY would anyone need to do such a thing??...Please enlighten me on the benefits of doing such a thing.
but this is something new to me ...
What does it mean when I see **...as in "void ** FunctionName" or
*& as in "SentMail*& Envelope"?
Can you tell me what ** and *& do?
My guess is that it's a pointer to a pointer, and a pointer to a reference...but if I'm right WHY would anyone need to do such a thing??...Please enlighten me on the benefits of doing such a thing.
** is a pointer to a pointer and *& is a reference to a pointer.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
** - pointer to pointer. In C you may use it when you are talking about an array of pointers, for example. Another example, when you you want to change a pointer in a function like here:
int Something(int** pointerToAnObject)
{
//do something
*pointerToAnObject = pointerToAnotherObject;
return 100;
}
Check here: http://www.hermetic.ch/cfunlib/ast_amp.htm
*& is the same (allows you to change the pointer in a function) as ** but in C++
int Something(int** pointerToAnObject)
{
//do something
*pointerToAnObject = pointerToAnotherObject;
return 100;
}
Check here: http://www.hermetic.ch/cfunlib/ast_amp.htm
*& is the same (allows you to change the pointer in a function) as ** but in C++
It looks like some of the special marks (aka double asterisk, and asterisk ampersand) are used when talking to the compiler.
"The double asterisk ('**') tells you and the compiler that the variable in question must be a pointer to another pointer. Simple, huh? :) So, when it is later referred to with brackets or double brackets, the compiler knows that it is legal to do so. " ~ http://www.ee.oulu.fi/research/tklab/courses/521419A/c_intro.html (right before the Structures section)
Also
"Compound pointers: int **p; or int** p; Read: p is a pointer to a pointer to an int.
(Also int ***p; and so on.)" ~ http://www.hermetic.ch/cfunlib/ast_amp.htm
And if I'm not mistaken the *& will dereference an object and then use that object as a pointer to a third object, but I couldn't find any info to back that.
"The double asterisk ('**') tells you and the compiler that the variable in question must be a pointer to another pointer. Simple, huh? :) So, when it is later referred to with brackets or double brackets, the compiler knows that it is legal to do so. " ~ http://www.ee.oulu.fi/research/tklab/courses/521419A/c_intro.html (right before the Structures section)
Also
"Compound pointers: int **p; or int** p; Read: p is a pointer to a pointer to an int.
(Also int ***p; and so on.)" ~ http://www.hermetic.ch/cfunlib/ast_amp.htm
And if I'm not mistaken the *& will dereference an object and then use that object as a pointer to a third object, but I couldn't find any info to back that.
ASKER
jkr,
void foo (char ** p) means that p is a pointer that points to another pointer that points to a character variable...did i get that right?
and void foo (char *& p) means that p is a reference to a pointer that points to a character variable...do i have that right?
so if you call foo with the memory address of a pointer as its argument..you're calling a pointer to a pointer?
and if you call foo with a pointer to a char variable as its argument..you're calling a reference to a pointer?
do i have this right?
void foo (char ** p) means that p is a pointer that points to another pointer that points to a character variable...did i get that right?
and void foo (char *& p) means that p is a reference to a pointer that points to a character variable...do i have that right?
so if you call foo with the memory address of a pointer as its argument..you're calling a pointer to a pointer?
and if you call foo with a pointer to a char variable as its argument..you're calling a reference to a pointer?
do i have this right?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, thanks for everyone's input...I basically checked off the comments I found to be helpful and let EE distribute the points accordingly. I feel JKR should get the bulk of the points for providing me with an example that I understand and for being the first to respond..