What will be the output of the following C++ code?

int x = 10;
int *p = &x;
int **q = &p;
cout << **q;
                        

Options

  • A. 10
  • B. Address of x
  • C. Address of p
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. 10

Detailed Explanation

Answer: (A) 10

p is a pointer to x, while q is a pointer to the pointer p.

*q gives p, and another dereference, **q, gives the value of x.

Since x = 10, the output is 10.