Search code examples
c++pointerspointer-to-pointer

What value does a Pointer to a Pointer print if not a single dereference operator is used at all?


I have tried the output of the following code. But, i don't yet understand what might the value of q represent.

I understand that the *q points to p implying that, printing *q would print the address of p, where as **q would print the value at the address p points to, i.e., x(=5).

#include <iostream>
using namespace std;
int main()
{
    int x=5;
    int *p,**q;
    p=&x;
    q=&p;
    cout<<q;
    return 0;
}

So what does q alone represent? What is that value that is printed when just q is printed?


Solution

  • You say:

    printing *q would print the address of p

    However this is not true. Printing q would print the address of p. After all, you assigned that in doing q = &p;.

    Printing *q would print the value of p , which is the address of x.