im just curious on the purpose of pointers to pointers and when i would actually ever find the use of using one! thx

Recommended Answers

All 3 Replies

Here's one, passing arguments to a program with argv.

int main(int argc, char**argv)
{}

I'm going to turn the question around: You can have a pointer to int, or a pointer to double, or a pointer to a class object, or a pointer to a function, or a pointer to an object of any of a bunch of other types I've left out. What do you think is so special about pointers that you wouldn't want to allow a pointer to point to one?

One purpose I use pointers to pointers is so that other functions can allocate memory for a pointer declared in another function. This is especially useful in building linked lists, which you will eventually discover during your studies.

void foo(char** pointer)
{
   *pointer = new char[255];
}

int main()
{
   char* p = NULL;
   foo(&p);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.