Jump to content
  • Advertisement
Sign in to follow this  
thedodgeruk

** not a clue what this means , can you help

This topic is 3003 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

this is a stupid question i know that a * denors a pointer , as in

float *foo ;


i have seen ** a few times in code , but i cant seam to find out what it means , can any one help please

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by thedodgeruk
this is a stupid question i know that a * denors a pointer , as in

float *foo ;


i have seen ** a few times in code , but i cant seam to find out what it means , can any one help please


Pointer to pointer. 'double pointer'

Share this post


Link to post
Share on other sites

int *p ; //pointer-to-int
string *s; //pointer-to-string
float** f; //pointer-to-(pointer-to-float)
string**ss; //pointer-to-(pointer-to-string)

int*** ppp; //pointer-to-(pointer-to-(pointer-to-int) );
//...

Share this post


Link to post
Share on other sites
Quote:
Original post by thedodgeruk
this is a stupid question i know that a * denors a pointer , as in

float *foo ;

i have seen ** a few times in code , but i cant seam to find out what it means , can any one help please
Sometimes you want a pointer to a pointer which is what ** means. For an example:
float foo = 1.0;
float fud = 2.0;
std::cout << foo << " " << fud << "\n";
float * bar = &foo;
float * buz = &fud;
float ** gaz = &bar;
**gaz=3.0f;
gaz = &buz;
**gaz=4.0f;
std::cout << foo << " " << fud << "\n";
Untested code.

Pointers also have addresses and sometimes you want to modify a pointer through its address much like sometimes you want to modify a float through its address. You can create pointers to pointers to pointers and so on as well, although their use gets more and more rare the more '*' you add. Hope this helps.

edit: I forgot to explain **gaz. This just dereferences the pointer twice to get to an actual float.

Share this post


Link to post
Share on other sites
An example where you could use such a thing is if you want to write a function to swap the contents of two pointers in C, leaving the pointees untouched:

void swap(int **a, int **b)
{
int *temp = *a;
*a = *b;
*b = temp;
}


An example which you probably have seen is the arguments to main(). Traditionally, main accepts either zero or two arguments (on rare occasions three or more):

int main(int argc, char **argv)
{
for(int i = 0 ; i < argc ; ++i) {
// examine the argument, the C-string in argv
}
}


You might be more familiar with main being declared as "int main(int argc, char *argv[])", but due to the way function arguments work this is treated as a pointer to a pointer.

In C++ there is rarely a need for double pointers, as we generally have more sophisticated techniques that are more explicit about intent.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!