C++ Pointer to Pointer


  • The pointer is known as a variable containing the address of another variable.
  • The pointer variables also have an address.
  • The pointer variable containing the address of another pointer variables is called a pointer to pointer.
  • This chain can be continued to an extent.

Syntax:

int **p2; //Pointer to Pointer

C++ pointer to pointer


Example:-

#include <iostream>     
using namespace std;

int main() 
{   
    int x=20;   
    int *p1,**p2;  
    p1=&x; /* x address store in p1 pointer variable */
    p2=&p1; /* double pointer */
   
    cout << "Address of x variable is " << &x << endl;
    cout << "Address of p1 variable is " << p1 << endl;
    cout << "Address of p2 variable is " << p2 << endl;
    
    cout << "Value of *p1 variable is  " << *p1 << endl;
    cout << "Value of **p2 variable is  " << **p2 << endl;
    return 0;
}



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.