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.
LVL 1
shaolinfunkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
** is a pointer to a pointer and *& is a reference to a pointer.
0
jkrCommented:
E.g.
const char* text = "Test";

void foo(char** p) {

  *p = text; // 'p' now points to 'text'
}

void foo(char*& p) {

  p = text; // 'p' now points to 'text'
}

int main () {

  char* p;

  foo(&p); // calls void foo(char** p)

  foo(p); // calls void foo(char*& p)

  return 0;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pgnatyukCommented:
** - 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++
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

JbrennonCommented:
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.


0
shaolinfunkAuthor Commented:
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?
0
evilrixSenior Software Engineer (Avast)Commented:
>> 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?

Correct

>> 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?

Correct

Read it from right to left as you say it is what it is.
0
pgnatyukCommented:
Only your first sentence is right.

If you are talking about the strings - char* means the string, an array of characters, so char** means a pointer to this string, a pointer to an array of characters. char*& means a reference to this array of characters.

If you have
char *s1 = "Hello";
char *s2 = "World";

you can write:
char** p1 = &s1;
char** p2 = &s2;

0
jkrCommented:
>>do i have this right?

Basically yes, except

>>and if you call foo with a pointer to a char variable as its argument..you're
>>calling a reference to a pointer?

That latter case would be a regular 'call by value', i.e.

void foo(char* p) {

  // can only change what 'p' points to, changes to 'p' itself
  // are only local to this function.
}

Open in new window

0
shaolinfunkAuthor Commented:
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..  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.