# Thread: Pointer to a Pointer

1. ## Pointer to a Pointer

A couple of us are having a small debate over explicitly declaring a pointer to a pointer. This is how I explained it:

**p can be assigned 'pointer objects'

whereas

*p is assigned addresses in memory.

Is this a valid explaination?

I attempted to google this, but as I expected, many tutorials on pointers.. but nothing specifically addressing (pardon the pun) my question.[/edit]

2. Sure.
It may be a little confusing (it was to me at first) because I read "*p" as a dereference, making it not-a-pointer.

Explanations with code examples will clear that sort of stuff up.

gg

3. This is my main argument:

Code:
```int **pp;

int *p;

int i = 5;

p  = &i;       // p now points to i

pp = &p;       // pp now points to p, which points to i

//dereferencing p will result in 5
cout << *p;

//dereferencing pp will only result in the memory address stored in p
cout << *pp;

//double dereferencing pp will result in 5
cout << **pp;```

4. I don't know if im right or not. Here is an example to test out how I understand a pointer to a pointer:
Code:
```#include <iostream>

using namespace std;

int main()
{
int i=5;
int *p=&i;
int **pp=&p;
cout<<"&i: "<<&i<<" "<<"&p: "<<&p<<" "<<"&pp: "<<&pp<<endl;
cout<<"&i: "<<&i<<" "<<"p: "<<p<<" "<<"pp: "<<pp<<endl;
cout<<"**pp: "<<**pp<<endl;
system("PAUSE");
}```
A Pointer accepts the address of the data type it is. While a Pointer to a Pointer accepts the data type of an int and a pointer.

Therefore I think of it like this.
A Pointer such as int *p expects to get the address of an int. While a Pointer to a pointer such as: int** p expects to get the address of an int*. Making the Pointer apart of the datatype it expects.
And when you dereference a pointer to a pointer. it Deferences the copy of the address in the pointer it points too.
Help me know if I understand it right or wrong. Thanks

5. >Is this a valid explaination?
Yes, but it makes a distinction where none exists. A pointer is very simple, it holds an address. T *p holds the address of an object of type T and is called a pointer for convenience. T **p holds the address of a pointer to an object of type T. The same logic holds for however many levels of indirection you want: T *****p holds the address of a pointer to a pointer to a pointer to a pointer to T.

6. Ok I think I got a better explaination of a pointer to a pointer. I will not give up. A Pointer expects type Datatype* and a pointer to a pointer Expects type datatype**. the First is pointing to just an address. and the pointer to a pointer points to the address of another address. It uses the Address of the pointer to point to. but Deferences the address within the Pointer.

7. New approached to explainations
A pointer to a pointer Is a Variable that uses two layers of Indirection while a Pointer just uses one Layer of Indirection
The Number of * shows how many indirections has must be used.

8. hmm... I prefferd RoDs d: